Documentation
¶
Index ¶
- type Encryption
- type Field
- 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) HandleError(w http.ResponseWriter, err error, logger *log.Logger) bool
- 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) Validator(data url.Values) *Validation
- func (t *Tools) WriteJSON(w http.ResponseWriter, status int, data interface{}, headers ...http.Header) error
- func (t *Tools) WriteXML(w http.ResponseWriter, status int, data interface{}, headers ...http.Header) error
- type UploadedFile
- type Validation
- func (v *Validation) AddError(key, message string)
- func (v *Validation) Check(ok bool, key, message string)
- func (v *Validation) Has(field string, r *http.Request) bool
- func (v *Validation) IsDateISO(field Field)
- func (v *Validation) IsEmail(field Field)
- func (v *Validation) IsFloat(field Field)
- func (v *Validation) IsInt(field Field)
- func (v *Validation) IsLength(field Field, length int)
- func (v *Validation) NoSpaces(field Field)
- func (v *Validation) Required(fields ...Field)
- func (v *Validation) Valid() bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Encryption ¶ added in v2.4.0
type Encryption struct {
Key []byte
}
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) HandleError ¶ added in v2.6.0
HandleError wraps ErrorJSON - outputs the error JSON or writes to the logger on failure
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
func (*Tools) Validator ¶ added in v2.1.0
func (t *Tools) Validator(data url.Values) *Validation
Validator creates an instance of a Validation based on form values. You can pass nil to this constructor to use the validation functions without an Http form
type UploadedFile ¶
UploadedFile is a struct used to save information about an uploaded file
type Validation ¶ added in v2.1.0
func (*Validation) AddError ¶ added in v2.1.0
func (v *Validation) AddError(key, message string)
AddError adds an error to the current Validator instance
func (*Validation) Check ¶ added in v2.1.0
func (v *Validation) Check(ok bool, key, message string)
Check takes any expression that can be evaluated to a bool and adds an error if result is false
func (*Validation) Has ¶ added in v2.1.0
func (v *Validation) Has(field string, r *http.Request) bool
Has checks if an Http form contains a field
func (*Validation) IsDateISO ¶ added in v2.1.0
func (v *Validation) IsDateISO(field Field)
IsDateISO checks if a form field is an ISO date (YYYY-MM-DD) and adds an error if result is false
func (*Validation) IsEmail ¶ added in v2.1.0
func (v *Validation) IsEmail(field Field)
IsEmail checks if a Field contains a valid email and adds an error if result is false
func (*Validation) IsFloat ¶ added in v2.1.0
func (v *Validation) IsFloat(field Field)
IsFloat checks if a Field is a floating point number and adds an error if result is false
func (*Validation) IsInt ¶ added in v2.1.0
func (v *Validation) IsInt(field Field)
IsInt checks if a Field is an integer
func (*Validation) IsLength ¶ added in v2.1.0
func (v *Validation) IsLength(field Field, length int)
IsLength checks if a field is at least a specific length and adds an error if result is false
func (*Validation) NoSpaces ¶ added in v2.1.0
func (v *Validation) NoSpaces(field Field)
NoSpaces checks if a Field contains spaces and adds an error if result is false
func (*Validation) Required ¶ added in v2.1.0
func (v *Validation) Required(fields ...Field)
Required checks a variadic list of Field and adds an error if a field is blank
func (*Validation) Valid ¶ added in v2.1.0
func (v *Validation) Valid() bool
Valid returns true if the current Validator contains no errors, otherwise false