Documentation ¶
Index ¶
- func FileDelete(path string) error
- func FileExists(path string) bool
- func FileTouch(path string) (err error)
- func Int64FromURL(r *http.Request, name string, standard int64) int64
- func IntFromURL(r *http.Request, name string, standard int) int
- func IsJpegFile(buf []byte) bool
- func IsPdfFile(buf []byte) bool
- func IsPngFile(buf []byte) bool
- func IsZipFile(buf []byte) bool
- func StringArrayFromURL(r *http.Request, name string, standard []string) []string
- func StringArrayToIntArray(values []string) ([]int, error)
- func StringFromURL(r *http.Request, name string, standard string) string
- func Time(t time.Time) time.Time
- func ToH(z interface{}) map[string]interface{}
- type DummyWriter
- type FileCategory
- type FileHandle
- func NewAvatarFileHandle(userID int64) *FileHandle
- func NewMaterialFileHandle(ID int64) *FileHandle
- func NewPrivateTestFileHandle(ID int64) *FileHandle
- func NewPublicTestFileHandle(ID int64) *FileHandle
- func NewSheetFileHandle(ID int64) *FileHandle
- func NewSubmissionFileHandle(ID int64) *FileHandle
- func NewSubmissionsCollectionFileHandle(courseID int64, sheetID int64, taskID int64, groupID int64) *FileHandle
- func (f *FileHandle) Delete() error
- func (f *FileHandle) Exists() bool
- func (f *FileHandle) GetContentType() (string, error)
- func (f *FileHandle) Path() string
- func (f *FileHandle) Sha256() (string, error)
- func (f *FileHandle) WriteToBody(w http.ResponseWriter) error
- func (f *FileHandle) WriteToBodyWithName(publicFilename string, w http.ResponseWriter) error
- func (f *FileHandle) WriteToDisk(r *http.Request, fieldName string) (string, error)
- type FileManager
- type H
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Int64FromURL ¶
Int64FromURL will read an URL parameter like /api/?some_int=3
func IntFromURL ¶
IntFromURL will read an URL parameter like /api/?some_int=3
func IsJpegFile ¶
IsJpegFile checks if file is jpg file based on magic number
func StringArrayFromURL ¶
StringArrayFromURL will read an URL parameter like /api/?some_strings=foo,bar
func StringArrayToIntArray ¶
StringArrayToIntArray converts a list of strings into a list of int or failes
func StringFromURL ¶
StringFromURL will read an URL parameter like /api/?some_string=foo
Types ¶
type DummyWriter ¶
type DummyWriter struct{}
DummyWriter is a writer which does nothing (use when writing to disk)
func (DummyWriter) WriteHeader ¶
func (h DummyWriter) WriteHeader(statusCode int)
WriteHeader does nothing
type FileCategory ¶
type FileCategory int32
FileCategory represents the categorie any upload is associated with
const ( AvatarCategory FileCategory = 0 SheetCategory FileCategory = 1 PublicTestCategory FileCategory = 2 PrivateTestCategory FileCategory = 3 MaterialCategory FileCategory = 4 SubmissionCategory FileCategory = 5 SubmissionsCollectionCategory FileCategory = 6 )
all categories
type FileHandle ¶
type FileHandle struct { Category FileCategory ID int64 // an unique identifier (e.g. from database) Extensions []string // MaxBytes bytefmt.ByteSize // 0 means no limit Infos []int64 }
FileHandle represents all information for file being uploaded or downloaded.
func NewAvatarFileHandle ¶
func NewAvatarFileHandle(userID int64) *FileHandle
NewAvatarFileHandle will handle user avatars. We support jpg only.
func NewMaterialFileHandle ¶
func NewMaterialFileHandle(ID int64) *FileHandle
NewMaterialFileHandle will handle course slides or extra material (zip files).
func NewPrivateTestFileHandle ¶
func NewPrivateTestFileHandle(ID int64) *FileHandle
NewPrivateTestFileHandle will handle the testing framework for private unit tests (zip files).
func NewPublicTestFileHandle ¶
func NewPublicTestFileHandle(ID int64) *FileHandle
NewPublicTestFileHandle will handle the testing framework for public unit tests (zip files).
func NewSheetFileHandle ¶
func NewSheetFileHandle(ID int64) *FileHandle
NewSheetFileHandle will handle exercise sheets (zip files).
func NewSubmissionFileHandle ¶
func NewSubmissionFileHandle(ID int64) *FileHandle
NewSubmissionFileHandle will handle homework/exercise submissions (zip files).
func NewSubmissionsCollectionFileHandle ¶
func NewSubmissionsCollectionFileHandle(courseID int64, sheetID int64, taskID int64, groupID int64) *FileHandle
NewSubmissionsCollectionFileHandle will handle a collection of submissions.
func (*FileHandle) Exists ¶
func (f *FileHandle) Exists() bool
Exists checks if a file really exists.
func (*FileHandle) GetContentType ¶
func (f *FileHandle) GetContentType() (string, error)
GetContentType tries to predict the content type without reading the entire file. There are some issues with this function as it cannot distinguish between zip and octstream.
func (*FileHandle) Path ¶
func (f *FileHandle) Path() string
Path return the path to a file using the config
func (*FileHandle) Sha256 ¶
func (f *FileHandle) Sha256() (string, error)
Sha256 computes the checksum and return it as a string
func (*FileHandle) WriteToBody ¶
func (f *FileHandle) WriteToBody(w http.ResponseWriter) error
WriteToBody will write a file from disk to the http response (download process)
func (*FileHandle) WriteToBodyWithName ¶
func (f *FileHandle) WriteToBodyWithName(publicFilename string, w http.ResponseWriter) error
WriteToBodyWithName reads a file from disk a writes it in the HTTP response (download)
func (*FileHandle) WriteToDisk ¶
WriteToDisk will save uploads from a http request to the directory specified in the config.