Documentation ¶
Index ¶
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.5.1
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 UseJSONTag ¶ added in v0.5.1
func UseJSONTag()
UseJSONTag will use the "json" struct field tag values instead of "uri" for determining the expected querystring parameter name. JSON specific struct tag options such as "omitempty" and "string" are ignored.
Types ¶
This section is empty.