Documentation ¶
Index ¶
- type JSONResponse
- type Tools
- func (t *Tools) CreateDirIfNotExist(path string) error
- func (t *Tools) DownloadStaticFile(w http.ResponseWriter, r *http.Request, pathName, fileName, displayName string)
- func (t *Tools) ErrorJSON(w http.ResponseWriter, err error, status ...int) error
- func (t *Tools) PushJSONToRemoteService(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 JSONResponse struct { Error bool `json:"error"` Message string `json:"message"` Data interface{} `json:"data,omitempty"` }
JSONResponse is used hold and transport JSON
type Tools ¶
type Tools struct { AllowedFileTypes []string MaxFileSize int MaxJSONPayloadSize int AllowUnknownFields bool }
Tools is used to instantiate this module. Any variable of this type will have access to all methods with the receiver *Tools
func (*Tools) CreateDirIfNotExist ¶
CreateDirIfNotExist creates a directory and all necessary parents, if it does not exist
func (*Tools) DownloadStaticFile ¶
func (t *Tools) DownloadStaticFile(w http.ResponseWriter, r *http.Request, pathName, fileName, displayName string)
DownloadStaticFile downloads a file and forces the browser not to open/display it by setting content disposition; (specification of the file display name is also available)
func (*Tools) ErrorJSON ¶
ErrorJSON takes an error and an optional status code, then generates and sends a JSON error message
func (*Tools) PushJSONToRemoteService ¶
func (t *Tools) PushJSONToRemoteService(uri string, data interface{}, client ...*http.Client) (*http.Response, int, error)
PushJSONToRemoteService posts JSON data to remote service, returning a response, status code and any error
func (*Tools) RandomString ¶
RandomString returns string of random characters of length n, generated from randomStringSource
func (*Tools) ReadJSON ¶
ReadJSON attempts to read request body and converts from JSON into a data variable
func (*Tools) UploadFiles ¶
func (t *Tools) UploadFiles(r *http.Request, uploadDir string, rename ...bool) ([]*UploadedFile, error)
UploadFiles allows uploading multiple files in one action to a specified directory with, if required, random naming. A slice containing newly named files, original file names, file size is returned and potentially an error. If the optional last parameter is set to true then files are not renamed but retain their original file names.
func (*Tools) UploadOneFile ¶
func (t *Tools) UploadOneFile(r *http.Request, uploadDir string, rename ...bool) (*UploadedFile, error)
UploadOneFile convenience method which restricts to uploading only one file
type UploadedFile ¶
UploadedFile is used to hold information about an uploaded file