Documentation ¶
Index ¶
- func Header(value reflect.Value, map2strs map[string][]string) (err error)
- func Query(value reflect.Value, map2strs map[string][]string) (err error)
- func Session(sess, value reflect.Value) error
- func Set(v reflect.Value, s string) error
- func SetArray(v reflect.Value, array []string) error
- func SetFloat(v reflect.Value, s string) error
- func SetInt(v reflect.Value, s string) error
- func SetUint(v reflect.Value, s string) error
- func Traverse(value reflect.Value, convertNilPtr bool, ...)
- func TraverseType(typ reflect.Type, fn func(f reflect.StructField))
- func ValidateHeader(typ reflect.Type)
- func ValidateQuery(typ reflect.Type)
- func ValidateRespHeader(typ reflect.Type)
- func WriteRespHeader(value reflect.Value, header http.Header)
- type ParamConverter
- type ParamField
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Query ¶
Example ¶
var v struct { Id int Name string `json:"userName"` Desc string `json:",omitempty"` Array []int `json:"array,omitempty"` X int Y string `json:"-"` } fmt.Println(Query(reflect.ValueOf(&v), map[string][]string{})) fmt.Printf("%+v\n", v) fmt.Println(Query(reflect.ValueOf(&v), map[string][]string{ "id": {"9"}, "userName": {"LiLei"}, "Desc": {"description"}, "array[]": {"1", "2", "3"}, })) fmt.Printf("%+v\n", v) fmt.Println(Query(reflect.ValueOf(&v), map[string][]string{ "x": {"a"}, })) fmt.Println(v.X)
Output: <nil> {Id:0 Name: Desc: Array:[] X:0 Y:} <nil> {Id:9 Name:LiLei Desc:description Array:[1 2 3] X:0 Y:} req.Query.X: strconv.ParseInt: parsing "a": invalid syntax 0
func Set ¶
Example ¶
var t struct { V string } fmt.Println(Set(reflect.ValueOf(&t), "XX")) fmt.Println(t) var t2 testUnmarshaler fmt.Println(Set(reflect.ValueOf(&t2), "XX")) fmt.Println(t2)
Output: invalid character 'X' looking for beginning of value {} <nil> {XX}
func SetArray ¶
Example ¶
var v = struct { Slice []string Array [3]int Json []struct { Id int Name string } }{} if err := SetArray(reflect.ValueOf(&v.Slice), []string{"a", "bc", "d"}); err != nil { log.Panic(err) } if err := SetArray(reflect.ValueOf(&v.Array), []string{"1", "2"}); err != nil { log.Panic(err) } if err := SetArray(reflect.ValueOf(&v.Json), []string{ `{"id": 3, "name": "f" }`, "{}", }); err != nil { log.Panic(err) } fmt.Println(v.Slice) fmt.Println(v.Array) fmt.Println(v.Json)
Output: [a bc d] [1 2 0] [{3 f} {0 }]
func TraverseType ¶
func TraverseType(typ reflect.Type, fn func(f reflect.StructField))
func ValidateHeader ¶
func ValidateQuery ¶
func ValidateRespHeader ¶
Types ¶
type ParamConverter ¶
type ParamConverter struct {
// contains filtered or unexported fields
}
func GetParamConverter ¶
func GetParamConverter(typ reflect.Type, path string) ParamConverter
type ParamField ¶
type ParamField struct { ParamIndex int reflect.StructField }
Click to show internal directories.
Click to hide internal directories.