google / google/go-querystring
Add support for struct field name casing options
- Dominant language
- Go
- Stars
- 2.1k
- Forks
- 188
- Avg merge
- 10h 23m
- Merged PRs (30d)
- 1
Description
TL;DR: Add support for camelCase and snake_case (commonly used formats for URL encoding) options in `query.Values()` function.
This package, by default, uses the struct's field names for URL query parameters. While the package supports defining custom field names using the `url` field tag, it is not possible add custom tags in certain scenarios, for example:
1. When using external packages' struct definitions.
2. When using structs that are tool-generated (protobuf, for example).
query/encode.go
```
package query
...
type Case int32
const (
CASE_DEFAULT Case = 0
CASE_CAMEL Case = 1
CASE_SNAKE Case = 2
CASE_PASCAL Case = 3
)
type Options struct {
EncodingCase Case
}
func Values(v interface{}, opts Options) (url.Values, error) {
...
}
```
usage.go
```
import "github.com/google/go-querystring/query"
import "some/external/package"
...
v, _ := query.Values(package.SomeStruct{}, Options{EncodingCase: query.CASE_CAMEL})
```
Contributor guide
Assessment
This issue has not been assessed yet.