gorilla / schema

Package gorilla/schema fills a struct with form values.
https://gorilla.github.io
BSD 3-Clause "New" or "Revised" License
1.39k stars 231 forks source link

fix unexported fields #179

Closed tonybase closed 3 years ago

tonybase commented 3 years ago

Fixes convert to protobuf known types failure.

enc := schema.NewEncoder()
enc.SetAliasTag("json")
enc.RegisterEncoder(&durationpb.Duration{}, func(v reflect.Value) string {
    return "100s"
})

dec := schema.NewDecoder()
dec.SetAliasTag("json")
dec.RegisterConverter(&durationpb.Duration{}, func(v string) reflect.Value {
    d, err := time.ParseDuration(v)
    if err != nil {
        return reflect.Value{}
    }
    return reflect.ValueOf(durationpb.New(d))
})

References: https://github.com/golang/go/blob/master/src/encoding/json/encode.go#L1244 https://github.com/go-kratos/kratos/pull/1152

stale[bot] commented 3 years ago

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.