Documentation ¶
Index ¶
Examples ¶
Constants ¶
View Source
const ( MIMEJSON = "application/json" MIMEHTML = "text/html" MIMEXML = "application/xml" MIMEXML2 = "text/xml" MIMEPlain = "text/plain" MIMEPOSTForm = "application/x-www-form-urlencoded" MIMEMultipartPOSTForm = "multipart/form-data" )
MIME
Variables ¶
View Source
var ( JSON = jsonBinding{} XML = xmlBinding{} Form = formBinding{} Query = queryBinding{} FormPost = formPostBinding{} FormMultipart = formMultipartBinding{} )
Binding
Functions ¶
This section is empty.
Types ¶
type Binding ¶
Binding http binding request interface.
Example ¶
package main import ( "fmt" "log" "net/http" ) type Arg struct { Max int64 `form:"max" validate:"max=10"` Min int64 `form:"min" validate:"min=2"` Range int64 `form:"range" validate:"min=1,max=10"` // use split option to split arg 1,2,3 into slice [1 2 3] // otherwise slice type with parse url.Values (eg:a=b&a=c) default. Slice []int64 `form:"slice,split" validate:"min=1"` } func main() { req := initHTTP("max=9&min=3&range=3&slice=1,2,3") arg := new(Arg) if err := Form.Bind(req, arg); err != nil { log.Fatal(err) } fmt.Printf("arg.Max %d\narg.Min %d\narg.Range %d\narg.Slice %v", arg.Max, arg.Min, arg.Range, arg.Slice) } func initHTTP(params string) (req *http.Request) { req, _ = http.NewRequest("GET", "http://api.bilibili.com/test?"+params, nil) req.ParseForm() return }
Output: arg.Max 9 arg.Min 3 arg.Range 3 arg.Slice [1 2 3]
type StructValidator ¶
type StructValidator interface { // ValidateStruct can receive any kind of type and it should never panic, even if the configuration is not right. // If the received type is not a struct, any validation should be skipped and nil must be returned. // If the received type is a struct or pointer to a struct, the validation should be performed. // If the struct is not valid or the validation itself fails, a descriptive error should be returned. // Otherwise nil must be returned. ValidateStruct(interface{}) error // RegisterValidation adds a validation Func to a Validate's map of validators denoted by the key // NOTE: if the key already exists, the previous validation function will be replaced. // NOTE: this method is not thread-safe it is intended that these all be registered prior to any validation RegisterValidation(string, validator.Func) error //GetValidate return the default validate GetValidate() *validator.Validate }
StructValidator http validator interface.
var Validator StructValidator = &defaultValidator{}
Validator default validator.
Source Files ¶
Click to show internal directories.
Click to hide internal directories.