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) UploadOneFile(r *http.Request, uploadDir string, rename ...bool) (*UploadedFile, error)
- func (t *Tools) UploadedFiles(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 int AllowedFileTypes []string MaxJSONSize int AllowUnknownFields bool }
Tools is the type used to instantiate this module. Any variable of this type will have access to allthe methods with the reciever *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, p, file, displayName string)
DownLoadStaticFile downloads a file, and tries to force the browser to avoid displaying it in the browser window by setting content disposition. it also allows sepcification of the display name
func (*Tools) ErrorJSON ¶
ErrorJSON takes an error, and optionally a status code and generates 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 aribtary data to some URI as JSON, and returns the responce, 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 len n, using randomStringSource as the source for the string
func (*Tools) UploadOneFile ¶
func (t *Tools) UploadOneFile(r *http.Request, uploadDir string, rename ...bool) (*UploadedFile, error)
UploadOneFile is just a conveniience method that calls the UploadFiles, but expects only one file to be inthe upload.
func (*Tools) UploadedFiles ¶
func (t *Tools) UploadedFiles(r *http.Request, uploadDir string, rename ...bool) ([]*UploadedFile, error)
UploadFiles uploads one or more files to a specified dirrectory. and give the files a random name. It returns a slice containing the newly named files, the original file names, the size of the files, and potentially an error. if the optional last parameter is set to true, then we will not rename the files, but will use the original file names.
type UploadedFile ¶
UploadedFile is a struct used to save information about uploaded file