Documentation ¶
Index ¶
- type JSONResponse
- type Tools
- func (t *Tools) CreateDirIfNotExists(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(size 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 UploadFilesParams
- 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 all the methods with the reciever *Tools
func (*Tools) CreateDirIfNotExists ¶
CreateDirIfNotExists create a directory and all necessary parents if it does not exists
func (*Tools) DownloadStaticFile ¶
func (t *Tools) DownloadStaticFile(w http.ResponseWriter, r *http.Request, pathName, displayName string)
DownloadsStatic File downloads a file and tries to force the browser to avoid displaying it in the browser window by setting content disposition. It also alllows 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 interface{}, client ...*http.Client) (*http.Response, int, error)
PushJSONToRemote post 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 ¶
*
- Cria 2 variáveis s, que é um slice de runes com o tamanho passado e r que será um slice de runes baseado na string passada
- Itera sobre o s, pegando apenas o index
- p recebe um inteiro randomico
- x recebe p como um uint64 e y recebe o tamanho de r como um uint64
- s recebe no seu index a rune que está no slice r na posição resultante do calculo de módulos
- retorna o slice de runes s como uma string
RandomString returns a string of random characters of lenght 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 (*Tools) UploadOneFile ¶
type UploadFilesParams ¶
type UploadFilesParams struct {
// contains filtered or unexported fields
}
type UploadedFile ¶
UploadedFile is a struct used to save information about an uploaded file