mirror of
https://github.com/aykhans/dodo.git
synced 2025-07-02 00:16:20 +00:00
🔨 Restructure entire project logic
- Moved readers to the config package - Added an option to read remote config files - Moved the validation package to the config package and removed the validator dependency - Moved the customerrors package to the config package - Replaced fatih/color with jedib0t/go-pretty/v6/text - Removed proxy check functionality - Added param, header, cookie, body, and proxy flags to the CLI - Allowed multiple values for the same key in params, headers, and cookies
This commit is contained in:
36
types/duration.go
Normal file
36
types/duration.go
Normal file
@ -0,0 +1,36 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Timeout struct {
|
||||
time.Duration
|
||||
}
|
||||
|
||||
func (timeout *Timeout) UnmarshalJSON(b []byte) error {
|
||||
var v any
|
||||
if err := json.Unmarshal(b, &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)")
|
||||
}
|
||||
}
|
||||
|
||||
func (timeout Timeout) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(timeout.Duration.String())
|
||||
}
|
Reference in New Issue
Block a user