Documentation ¶
Index ¶
- type JSONResponse
- type Tools
- func (t *Tools) CreateDirIfNotExists(path string) error
- func (t *Tools) DownloadStaticFile(writer http.ResponseWriter, request *http.Request, ...)
- func (t *Tools) ErrorJSON(writer http.ResponseWriter, err error, status ...int) error
- func (t *Tools) PushJSONToRemote(uri string, data any, client ...*http.Client) (*http.Response, int, error)
- func (t *Tools) RandomString(n int) string
- func (t *Tools) ReadJSON(writer http.ResponseWriter, request *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(request *http.Request, uploadDir string, rename ...bool) (*UploadedFile, error)
- func (t *Tools) WriteJSON(writer http.ResponseWriter, status int, data interface{}, ...) 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 are the ONLY types of files that will be allowed to upload 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 the methods with the receiver *Tools
func (*Tools) CreateDirIfNotExists ¶
CreateDirIfNotExists creates a directory, and add all necessary parents, if it does not exist
func (*Tools) DownloadStaticFile ¶
func (t *Tools) DownloadStaticFile(writer http.ResponseWriter, request *http.Request, pathName, displayName string)
DownloadStaticFile downloads a file, and tries to force the browser to avoid displaying it in the browser windows 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 generates and sends a JSON error message
func (*Tools) PushJSONToRemote ¶
func (t *Tools) PushJSONToRemote(uri string, data any, client ...*http.Client) (*http.Response, int, error)
PushJSONToRemote 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, using randomStringSource as the source for the string
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 handles the process of uploading files to the server
func (*Tools) UploadOneFile ¶
type UploadedFile ¶
UploadedFile is a struct used to save information about an uploaded file