diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2017-06-30 14:36:34 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2017-06-30 14:36:34 +0200 |
| commit | 909ccbe28fb62774ef7cb0f035ab9cf41927c06a (patch) | |
| tree | 568fe9f7738d44a1d7bc62f933cb662f7b99ecd7 /pkg/config | |
| parent | ed1e09a88a3e43fb2a5aa70b6b5159b001d51c40 (diff) | |
pkg/config: support time.Time fields
Diffstat (limited to 'pkg/config')
| -rw-r--r-- | pkg/config/config.go | 3 | ||||
| -rw-r--r-- | pkg/config/config_test.go | 9 |
2 files changed, 12 insertions, 0 deletions
diff --git a/pkg/config/config.go b/pkg/config/config.go index fc77d2496..537b9f3d6 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -99,6 +99,9 @@ func checkUnknownFieldsStruct(val interface{}, prefix string, typ reflect.Type) if typ.Kind() != reflect.Struct { return nil } + if typ.PkgPath() == "time" && typ.Name() == "Time" { + return nil + } inner, err := json.Marshal(val) if err != nil { return fmt.Errorf("failed to marshal inner struct '%v%v':", prefix, err) diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index ee8a79661..6d3ce034e 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -8,6 +8,7 @@ import ( "fmt" "reflect" "testing" + "time" ) func TestLoad(t *testing.T) { @@ -29,6 +30,7 @@ func TestLoad(t *testing.T) { Box Nested Boq *Nested Arr []Nested + T time.Time } tests := []struct { @@ -162,6 +164,13 @@ func TestLoad(t *testing.T) { Config{}, "", }, + { + `{"t": "2000-01-02T03:04:05Z"}`, + Config{ + T: time.Date(2000, 1, 2, 3, 4, 5, 0, time.UTC), + }, + "", + }, } for i, test := range tests { t.Run(fmt.Sprint(i), func(t *testing.T) { |
