Documentation
¶
Index ¶
- type JSONResponse
- type Tools
- func (t *Tools) CreateDirIfNotExist(path string) error
- func (t *Tools) DownloadStaticFile(w http.ResponseWriter, r *http.Request, pathName, 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 JSONResponse struct {
Error bool `json:"error"`
Message string `json:"message"`
Data interface{} `json:"data,omitempty"`
}
JSONResponse is the type used for sending JSON around
type Tools ¶
type Tools struct {
MaxFileSize int64
AllowedFileTypes []string
MaxJSONSize int
AllowUnknownFields bool
}
Tools is the type used to instantiate this module Any variable of this type will have access to all methods with the receiver *Tools Also see https://developer.mozilla.org/en-US/docs/Web/HTTP/MIME_types/Common_types
func (*Tools) CreateDirIfNotExist ¶
CreateDirIfNotExist creates a directory, and all necessary parents
func (*Tools) DownloadStaticFile ¶
func (t *Tools) DownloadStaticFile(w http.ResponseWriter, r *http.Request, pathName, displayName string)
DownloadStaticFile downloads a file tries to force the browser to avoid displaying it in the browser window by setting content disposition. It also allows specification of the display name
func (*Tools) ErrorJSON ¶
ErrorJSON takes an error and optionally a status code, and sends a JSON error message
func (*Tools) PushJSONToRemote ¶
func (t *Tools) PushJSONToRemote(uri string, data interface{}, client ...*http.Client) (*http.Response, int, error)
PushJSONToRemote posts arbitrary data to some URL as JSON, and returns the response, status code, and error, if any The final parameter, client, is optional. 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 from json into a go data variable
func (*Tools) UploadFiles ¶
func (t *Tools) UploadFiles(r *http.Request, uploadDir string, rename ...bool) ([]*UploadedFile, error)
UploadFiles uploads one of more file to a specified directory, and give the files a random name if required. If the optional last parameter is set to false, it will not rename and use the original name.
func (*Tools) UploadOneFile ¶
func (t *Tools) UploadOneFile(r *http.Request, uploadDir string, rename ...bool) (*UploadedFile, error)
UploadOneFile is a convenience methods that calls UploadFiles, but expects only one file