mirror of
https://github.com/aykhans/dodo.git
synced 2025-09-05 10:43:37 +00:00
✨ Add yaml file reader to config
This commit is contained in:
@@ -34,3 +34,24 @@ func (timeout *Timeout) UnmarshalJSON(b []byte) error {
|
||||
func (timeout Timeout) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(timeout.Duration.String())
|
||||
}
|
||||
|
||||
func (timeout *Timeout) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||
var v any
|
||||
if err := unmarshal(&v); err != nil {
|
||||
return err
|
||||
}
|
||||
switch value := v.(type) {
|
||||
case float64:
|
||||
timeout.Duration = time.Duration(value)
|
||||
return nil
|
||||
case string:
|
||||
var err error
|
||||
timeout.Duration, err = time.ParseDuration(value)
|
||||
if err != nil {
|
||||
return errors.New("Timeout is invalid (e.g. 400ms, 1s, 5m, 1h)")
|
||||
}
|
||||
return nil
|
||||
default:
|
||||
return errors.New("Timeout is invalid (e.g. 400ms, 1s, 5m, 1h)")
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user