Documentation
¶
Index ¶
- func GetFieldString(value reflect.Value, sTag reflect.StructTag) string
- func Marshal(v interface{}) (s string)
- func MarshalUnescaped(v interface{}) string
- func SetField(value reflect.Value, s string, sField reflect.StructField) error
- func Unmarshal(uri string, v interface{}) error
- func UnmarshalQuery(query string, v interface{}) error
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetFieldString ¶
GetFieldString returns a string representation of a Value booleans become true/false nil pointers return "nil" slices combine elements with a comma. []int{1,2,3} -> "1,2,3"
Example ¶
name := "hello world"
s := GetFieldString(reflect.ValueOf(name), "")
fmt.Println(s)
var i *int
s = GetFieldString(reflect.ValueOf(i), "")
fmt.Println(s)
v := []int{2, 1, 3}
s = GetFieldString(reflect.ValueOf(v), "")
fmt.Println(s)
Output: hello world nil 2,1,3
func Marshal ¶
func Marshal(v interface{}) (s string)
Marshal a struct into a string representation of a uri Note: Marshal panics if a struct or pointer to a struct is not provided
Example ¶
v := struct {
Scheme string `uri:"scheme"`
Host string `uri:"host"`
Path string `uri:"path"`
Name string `uri:"name"`
Count int `uri:"num"`
}{
Scheme: "https",
Host: "localhost",
Path: "root/index.html",
Name: "Hello World",
Count: 11,
}
s := Marshal(v)
fmt.Println(s)
Output: https://localhost/root/index.html?name=Hello+World&num=11
func MarshalUnescaped ¶ added in v0.4.0
func MarshalUnescaped(v interface{}) string
MarshalUnescaped is the same as marshal but without url encoding the values
func SetField ¶
SetField converts the string s to the type of value and sets the value if possible. Pointers and slices are recursively dealt with by deferencing the pointer or creating a generic slice of type value. All structs and alias' that implement encoding.TextUnmarshaler are suppported
func Unmarshal ¶
Unmarshal copies a standard parsable uri to a predefined struct [scheme:][//[userinfo@]host][/]path[?query][#fragment] scheme:opaque[?query][#fragment]
Example ¶
v := struct {
Scheme string `uri:"scheme"`
Host string `uri:"host"`
Path string `uri:"path"`
Name string `uri:"name"`
Count int `uri:"num"`
}{}
s := "https://localhost/root/index.html?name=Hello+World&num=11"
Unmarshal(s, &v)
fmt.Printf("scheme:%s\nhost:%s\npath:%s\nname:%s\ncount:%d", v.Scheme, v.Host, v.Path, v.Name, v.Count)
Output: scheme:https host:localhost path:/root/index.html name:Hello World count:11
func UnmarshalQuery ¶ added in v0.6.1
UnmarshalQuery is a comparable to the url.ParseQuery()
Types ¶
This section is empty.
