Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrNonPointerTarget is returned when the given interface does not represent a pointer ErrNonPointerTarget = errors.New("invalid Unmarshal target. must be a pointer") // ErrInvalidURL is returned when the given *url.URL is nil ErrInvalidURL = errors.New("invalid url provided") )
Functions ¶
func Unmarshal ¶
Unmarshal attempts to parse query parameters from the specified URL and store any found values into the given interface
Example ¶
ExampleUnmarshal creates a dummy http request and unmarshals the data into a struct
package main import ( "fmt" "net/http" "net/url" "github.com/tomwright/queryparam" ) func main() { var err error var request = &http.Request{} request.URL, err = url.Parse("https://example.com/some/path?name=Tom&age=23") if err != nil { panic(err) } requestData := struct { Name string `queryparam:"name"` Age string `queryparam:"age"` }{} err = queryparam.Unmarshal(request.URL, &requestData) if err != nil { panic(err) } fmt.Println(requestData.Name + " is " + requestData.Age) }
Output: Tom is 23
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.