• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.github/workflows/H10-Mar-2021-

query/H10-Mar-2021-

.gitignoreH A D10-Mar-20217

.golangci.ymlH A D10-Mar-2021178

CONTRIBUTING.mdH A D10-Mar-20213.1 KiB

LICENSEH A D10-Mar-20211.4 KiB

README.mdH A D10-Mar-20211.7 KiB

go.modH A D10-Mar-202190

go.sumH A D10-Mar-2021278

README.md

1# go-querystring #
2
3[![Go Reference](https://pkg.go.dev/badge/github.com/google/go-querystring/query.svg)](https://pkg.go.dev/github.com/google/go-querystring/query)
4[![Test Status](https://github.com/google/go-querystring/workflows/tests/badge.svg)](https://github.com/google/go-querystring/actions?query=workflow%3Atests)
5[![Test Coverage](https://codecov.io/gh/google/go-querystring/branch/master/graph/badge.svg)](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
48