mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-01 11:08:10 +00:00
Unify time.Duration handling across framework and parseutil (#6935)
This removes a lot of duplicated code and adds time.Duration support to parseutil, needed by the jwt auth method.
This commit is contained in:
@@ -2,7 +2,6 @@ package framework
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
@@ -555,36 +554,11 @@ func (s *FieldSchema) DefaultOrZero() interface{} {
|
||||
if s.Default != nil {
|
||||
switch s.Type {
|
||||
case TypeDurationSecond:
|
||||
var result int
|
||||
switch inp := s.Default.(type) {
|
||||
case nil:
|
||||
return s.Type.Zero()
|
||||
case int:
|
||||
result = inp
|
||||
case int64:
|
||||
result = int(inp)
|
||||
case float32:
|
||||
result = int(inp)
|
||||
case float64:
|
||||
result = int(inp)
|
||||
case string:
|
||||
dur, err := parseutil.ParseDurationSecond(inp)
|
||||
if err != nil {
|
||||
return s.Type.Zero()
|
||||
}
|
||||
result = int(dur.Seconds())
|
||||
case json.Number:
|
||||
valInt64, err := inp.Int64()
|
||||
if err != nil {
|
||||
return s.Type.Zero()
|
||||
}
|
||||
result = int(valInt64)
|
||||
case time.Duration:
|
||||
result = int(inp.Seconds())
|
||||
default:
|
||||
resultDur, err := parseutil.ParseDurationSecond(s.Default)
|
||||
if err != nil {
|
||||
return s.Type.Zero()
|
||||
}
|
||||
return result
|
||||
return int(resultDur.Seconds())
|
||||
|
||||
default:
|
||||
return s.Default
|
||||
|
||||
Reference in New Issue
Block a user