...
1# go-querystring #
2
3[](https://pkg.go.dev/github.com/google/go-querystring/query)
4[](https://github.com/google/go-querystring/actions?query=workflow%3Atests)
5[](https://codecov.io/gh/google/go-querystring)
6
7go-querystring is a Go library for encoding structs into URL query parameters.
8
9## Usage ##
10
11```go
12import "github.com/google/go-querystring/query"
13```
14
15go-querystring is designed to assist in scenarios where you want to construct a
16URL using a struct that represents the URL query parameters. You might do this
17to enforce the type safety of your parameters, for example, as is done in the
18[go-github][] library.
19
20The query package exports a single `Values()` function. A simple example:
21
22```go
23type Options struct {
24 Query string `url:"q"`
25 ShowAll bool `url:"all"`
26 Page int `url:"page"`
27}
28
29opt := Options{ "foo", true, 2 }
30v, _ := query.Values(opt)
31fmt.Print(v.Encode()) // will output: "q=foo&all=true&page=2"
32```
33
34See the [package godocs][] for complete documentation on supported types and
35formatting options.
36
37[go-github]: https://github.com/google/go-github/commit/994f6f8405f052a117d2d0b500054341048fbb08
38[package godocs]: https://pkg.go.dev/github.com/google/go-querystring/query
39
40## Alternatives ##
41
42If you are looking for a library that can both encode and decode query strings,
43you might consider one of these alternatives:
44
45 - https://github.com/gorilla/schema
46 - https://github.com/pasztorpisti/qs
47 - https://github.com/hetiansu5/urlquery
View as plain text