convert

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 13, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Header(value reflect.Value, map2strs map[string][]string) (err error)

func Query

func Query(value reflect.Value, map2strs map[string][]string) (err error)
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)
Output:

<nil>
{Id:0 Name: Desc: Array:[] X:0 Y:}
<nil>
{Id:9 Name:LiLei Desc:description Array:[1 2 3] X:0 Y:}

func Session

func Session(sess, value reflect.Value) error

func Set

func Set(v reflect.Value, s string) error

func SetArray

func SetArray(v reflect.Value, array []string) error
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 SetFloat

func SetFloat(v reflect.Value, s string) error

func SetInt

func SetInt(v reflect.Value, s string) error

func SetUint

func SetUint(v reflect.Value, s string) error

func ValidateHeader

func ValidateHeader(typ reflect.Type)

func ValidateQuery

func ValidateQuery(typ reflect.Type)

func ValidateRespHeader

func ValidateRespHeader(typ reflect.Type)

func WriteRespHeader

func WriteRespHeader(value reflect.Value, header http.Header)

Types

type ParamConverter

type ParamConverter struct {
	// contains filtered or unexported fields
}

func GetParamConverter

func GetParamConverter(typ reflect.Type, path string) ParamConverter

func (ParamConverter) Convert

func (pc ParamConverter) Convert(param reflect.Value, paramsSlice []string) error

type ParamField

type ParamField struct {
	ParamIndex int
	reflect.StructField
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL