Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
func NewDecoder ¶
func (*Decoder) Decode ¶
func (d *Decoder) Decode(s DecoderSource, v interface{}) error
Example ¶
type QueryRequest struct { Name string `schema:"body"` Date time.Time `schema:"body"` AccessToken string `schema:"header" header:"Authorization"` Page uint32 `schema:"query" query:"p"` } u, err := url.Parse("http://localhost?p=3") if err != nil { log.Fatal(err) } httpreq := http.Request{ URL: u, PostForm: url.Values{ "name": []string{"Someone"}, "date": []string{"2018/12/25"}, }, Header: http.Header{ "Authorization": []string{"Token"}, }, } d, err := newDecoder() if err != nil { log.Fatal(err) } var reqData QueryRequest err = d.Decode(&httpRequestSource{&httpreq}, &reqData) if err != nil { log.Fatal(err) } fmt.Printf("%s %s %s %d\n", reqData.Name, reqData.Date.Format("2006-01-02"), reqData.AccessToken, reqData.Page)
Output: Someone 2018-12-25 Token 3
type DecoderSource ¶
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
func NewEncoder ¶
func (*Encoder) Encode ¶
func (e *Encoder) Encode(v interface{}, dst EncoderDestination) error
type EncoderDestination ¶
type FieldOptions ¶
format: sources[;flags], sources: source[,source]*, flags: [inline]
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
func NewParser ¶
func NewParser(optionsTag string, validSources []string, fieldNameConverter func(string) string) (*Parser, error)
optionsTag is used for retrieve field options, each source can have it's own name, if not specified, use name of first source or converted field name by default.
func (*Parser) RegisterTypes ¶
Click to show internal directories.
Click to hide internal directories.