diff options
author | Matthew Holt <mholt@users.noreply.github.com> | 2019-11-04 12:54:46 -0700 |
---|---|---|
committer | Matthew Holt <mholt@users.noreply.github.com> | 2019-11-04 12:54:46 -0700 |
commit | bf363f061d03f33a8301466c9c0e2a89d75542c0 (patch) | |
tree | 496009e72f51f12153498316ffb48f67ffdedc28 /caddy.go | |
parent | 7129f6c1c00103a403717a68a0d91965b818db5b (diff) |
reverse_proxy: Add UnmarshalCaddyfile for random_choose selection policy
Also allow caddy.Duration to be given integer values which are treated
like regular time.Duration values (nanoseconds).
Fixes #2856
Diffstat (limited to 'caddy.go')
-rw-r--r-- | caddy.go | 16 |
1 files changed, 11 insertions, 5 deletions
@@ -437,12 +437,18 @@ type Duration time.Duration // UnmarshalJSON satisfies json.Unmarshaler. func (d *Duration) UnmarshalJSON(b []byte) error { - dd, err := time.ParseDuration(strings.Trim(string(b), `"`)) - if err != nil { - return err + if len(b) == 0 { + return io.EOF } - *d = Duration(dd) - return nil + var dur time.Duration + var err error + if b[0] == byte('"') && b[len(b)-1] == byte('"') { + dur, err = time.ParseDuration(strings.Trim(string(b), `"`)) + } else { + err = json.Unmarshal(b, &dur) + } + *d = Duration(dur) + return err } // GoModule returns the build info of this Caddy |