From 1f8679d4b6ae8af19ebe15a3cc5a5a82d61c2d0d Mon Sep 17 00:00:00 2001 From: Will Norris Date: Wed, 24 Feb 2021 15:51:07 -0800 Subject: [PATCH 1/2] stash README changes --- README.md | 59 +++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 53 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 84be3cc..513af95 100644 --- a/README.md +++ b/README.md @@ -19,20 +19,67 @@ to enforce the type safety of your parameters, for example, as is done in the The query package exports a single `Values()` function. A simple example: -```go -type Options struct { +``` go +type opt struct { Query string `url:"q"` ShowAll bool `url:"all"` Page int `url:"page"` } -opt := Options{ "foo", true, 2 } -v, _ := query.Values(opt) +v, _ := query.Values(opt{"foo", true, 2}) fmt.Print(v.Encode()) // will output: "q=foo&all=true&page=2" ``` -See the [package godocs][] for complete documentation on supported types and -formatting options. +### Supported types and options ### + +The [package godocs][] are the authoritative source for documentation on +supported types and formatting options, but illustrative examples are provided +here as well. + +#### booleans + +By default, boolean values are encoded as the words "true" or "false": + +``` go +type opt struct { + V bool `url:"v"` +} + +query.Values(opt{true}) // result: "v=true" +``` + +Adding the `int` option causes the field to be encoded as a "1" or "0": + +``` go +type opt struct { + V bool `url:v,int` +} + +query.Values(opt{false}) // result: "v=0" +``` + +#### time + +By default, time values are encoded as RFC3339 timestamps: + +``` go +type opt struct { + V time.Time `url:"v"` +} + +query.Values(opt{false}) // result: "v=0" +``` + +Adding the `unix` option encodes as a UNIX timestamp (seconds since Jan 1, 1970) + +``` go +type opt struct { + V time.Time `url:"v,unix"` +} + +query.Values(opt{false}) // result: "v=0" +``` + [go-github]: https://github.com/google/go-github/commit/994f6f8405f052a117d2d0b500054341048fbb08 [package godocs]: https://pkg.go.dev/github.com/google/go-querystring/query From 933e771185ac05d912951a52c38ccb6277e4bbb2 Mon Sep 17 00:00:00 2001 From: Will Norris Date: Mon, 1 Mar 2021 09:01:55 -0800 Subject: [PATCH 2/2] remove comment about undesirable test values --- query/encode_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/query/encode_test.go b/query/encode_test.go index 03a5cf1..8487858 100644 --- a/query/encode_test.go +++ b/query/encode_test.go @@ -603,7 +603,7 @@ func TestValues_CustomEncodingPointer(t *testing.T) { url.Values{"v": {"1"}}, }, - // pointers to custom encoded types. (Values below are not necessarily desirable) + // pointers to custom encoded types. { struct { V *customEncodedIntPtr `url:"v"`