Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Marshal ¶
Marshal encodes the given value into URL query parameters with the default options.
Example ¶
type Object struct { Slice []int `url:"slice"` String string `url:"string"` } m := map[string]any{ "slice": []string{"100", "200"}, "int": 1, "map": map[string]any{ "slice": []string{"100", "200"}, "int": 1, }, "object": Object{ Slice: []int{1, 2}, String: "example", }, } values, err := urlvalues.Marshal(m) if err != nil { panic(err) } fmt.Println(values.Encode())
Output: int=1&map%5Bint%5D=1&map%5Bslice%5D=100&map%5Bslice%5D=200&object%5Bslice%5D=1&object%5Bslice%5D=2&object%5Bstring%5D=example&slice=100&slice=200
Types ¶
type Marshaler ¶
Marshaler is an interface that defines the method for encoding Go values into URL query parameters.
type MarshalerOptions ¶
type MarshalerOptions struct { // ArrayBrackets, when set to true, adds brackets to array/slice keys in the URL parameters. ArrayBrackets bool // ArrayDelimiter specifies a custom delimiter for joining slice values in the URL parameters. ArrayDelimiter string // IntBool when set to true, represents boolean values as integers (0 or 1). IntBool bool // TimeUnix time encoded in seconds. TimeUnix bool // TimeUnixMilli time encoded in milliseconds. TimeUnixMilli bool // TimeUnixNano time encoded in nanoseconds. TimeUnixNano bool // TimeLayout allows specifying a custom layout for time values if provided. TimeLayout string }
MarshalerOptions defines optional parameters for the Marshal function. These options only apply to maps, for structs the tag options are used.
Click to show internal directories.
Click to hide internal directories.