gorilla/schema

[feature] Encode slices as separator-delimited strings

gudvinr opened this issue · 1 comments

Is your feature request related to a problem? Please describe.

Sometimes it is required to encode array-like data in queries as strings of elements delimited by some separator.
For example, OAuth2 specification says:

The value of the scope parameter is expressed as a list of space-
delimited, case-sensitive strings.

So, in this case if you want to encode (or decode) field you need to implement custom decoder to write scope as space-delimited string.

It is fine if you only use []string but you also need to do so for slices of custom types like type Scope string separately. It's not possible to support arrays of different cardinality.

Describe the solution you'd like

Implement handling of additional options in struct tags such as space and comma to support commonly used delimiters to encode array-like data.

Describe alternatives you've considered

Write custom encoder and decoder for every slice type and register them in every instance of schema.Encoder and schema.Decoder.

stale commented

This issue has been automatically marked as stale because it hasn't seen a recent update. It'll be automatically closed in a few days.