separated httpcli from replaycli. Added config methods

nats
Paulo Simão 2021-10-11 11:53:57 -03:00
parent 4e142e5300
commit bf8aaa2ca0
1 changed files with 51 additions and 0 deletions

View File

@ -1,6 +1,8 @@
package types package types
import ( import (
"encoding/json"
"strconv"
"time" "time"
) )
@ -140,6 +142,55 @@ type Config struct {
Repo uint `json:"repo"` Repo uint `json:"repo"`
} }
func (c *Config) AsInt64() int64 {
i, err := strconv.ParseInt(c.V, 10, 64)
if err != nil {
return 0
}
return i
}
func (c *Config) AsInt32() int32 {
i, err := strconv.ParseInt(c.V, 10, 32)
if err != nil {
return 0
}
return int32(i)
}
func (c *Config) AsUint() uint {
i, err := strconv.ParseInt(c.V, 10, 32)
if err != nil {
return 0
}
return uint(i)
}
func (c *Config) AsInt() int {
i, err := strconv.ParseInt(c.V, 10, 16)
if err != nil {
return 0
}
return int(i)
}
func (c *Config) AsFloat64() float64 {
i, err := strconv.ParseFloat(c.V, 64)
if err != nil {
return 0
}
return i
}
func (c *Config) AsFloat32() float32 {
i, err := strconv.ParseFloat(c.V, 32)
if err != nil {
return 0
}
return float32(i)
}
func (c *Config) AsBool() bool {
return c.V == "true" || c.V == "1" || c.V == "t"
}
func (c *Config) AsJson(i interface{}) error {
return json.Unmarshal([]byte(c.V), i)
}
type Credentials struct { type Credentials struct {
Model Model
Name string `json:"name"` Name string `json:"name"`