Documentation
¶
Index ¶
- type JSONResponse
- type Tools
- func (t *Tools) CreateDirIfNotExist(pathDir string) error
- func (t *Tools) DownloadStaticFile(w http.ResponseWriter, r *http.Request, p, file, displayNaem string)
- func (t *Tools) ErrorJSON(w 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(w http.ResponseWriter, r *http.Request, data any) 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 any, 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 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 the methods with the receiver *Tools
func (*Tools) CreateDirIfNotExist ¶
CreateDirIfNotExist creates a directiroy, and all necessary parents, if it does not exist
func (*Tools) DownloadStaticFile ¶
func (t *Tools) DownloadStaticFile(w http.ResponseWriter, r *http.Request, p, file, displayNaem string)
DownloadStaticFile downloads a file, and tries to force the browser to avoid displaying it in the browser window by setting the Content-Disposition header. It also allows specification of the display name.
func (*Tools) ErrorJSON ¶
ErrorJSON takes an error, and optionally a response status code, and generates and sends
func (*Tools) PushJSONToRemote ¶
func (t *Tools) PushJSONToRemote(uri string, data any, client ...*http.Client) (*http.Response, int, error)
PushJSONToRemote posts arbitrary data to some URL as JSON. It returns the response, status code and error, if any. the final parameter, client, is optional. If not provided, the default http client is used.
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 data variable.
func (*Tools) UploadFiles ¶
func (*Tools) UploadOneFile ¶
type UploadedFile ¶
UploadedFile is a struct used to store information about an uploaded file.