Documentation
¶
Index ¶
- type JSONResponse
- type Tools
- func (t *Tools) CreateDirIfNotExist(path string) error
- func (t *Tools) DownloadStaticFile(w http.ResponseWriter, r *http.Request, p, file, displayName string)
- func (t *Tools) ErrorJSON(w http.ResponseWriter, err error, status ...int) error
- func (t *Tools) PushJSONToRemote(uri string, data interface{}, client ...*http.Client) (*http.Response, int, error)
- func (t *Tools) RandomString(n int) string
- func (t *Tools) ReadJSON(w http.ResponseWriter, r *http.Request, data interface{}) error
- func (t *Tools) Slugify(s string) (string, error)
- func (t *Tools) UploadFiles(r *http.Request, uploadDir string, rename ...bool) ([]*UploadedFile, error)
- func (t *Tools) UploadOneFile(r *http.Request, uploadDir string, rename ...bool) (*UploadedFile, error)
- func (t *Tools) WriteJSON(w http.ResponseWriter, status int, data interface{}, headers ...http.Header) error
- type UploadedFile
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type JSONResponse ¶
type Tools ¶
type Tools struct {
MaxFileSize int
AllowedFileTypes []string
MaxJSONSize int
AllowUnknownFields bool
}
Tools is the type we use to instantiate this module. Any variable of this type will have access to all the methods with the receiver *Tools
func (*Tools) CreateDirIfNotExist ¶
CreateDirIfNotExist create a directory, and all parent directories if it doesn't exist
func (*Tools) DownloadStaticFile ¶
func (t *Tools) DownloadStaticFile(w http.ResponseWriter, r *http.Request, p, file, displayName string)
DownloadStaticFile downloads a file, or sends it to the client. It also force the browser to download the file It also allows specification of the file name.
func (*Tools) ErrorJSON ¶
Error JSON takes an error and a status code, and writes a JOSN error message to the client
func (*Tools) PushJSONToRemote ¶
func (t *Tools) PushJSONToRemote(uri string, data interface{}, client ...*http.Client) (*http.Response, int, error)
PushJSONToRemote pushes arbitrary JSON data to a remote endpoint and returns the response, status code, and error if any The final parameter is an optional http client. If none is specified, we use the standard http.Client
func (*Tools) RandomString ¶
RandomString returns a string of random characters of length n
func (*Tools) ReadJSON ¶
ReadJSON tries to read the body of a request and converts it into JSON. If there is an error, we write the error in the response and return a 400 status code.
func (*Tools) UploadFiles ¶
func (t *Tools) UploadFiles(r *http.Request, uploadDir string, rename ...bool) ([]*UploadedFile, error)
UploadFiles upload one or more files to a particular location
func (*Tools) UploadOneFile ¶
func (t *Tools) UploadOneFile(r *http.Request, uploadDir string, rename ...bool) (*UploadedFile, error)
UploadOneFile upload one file to a particular location
type UploadedFile ¶
UploadedFile is a struct used to save information about an uploaded file