envconf/datatype.go

35 lines
626 B
Go
Raw Normal View History

2021-03-23 11:57:09 +00:00
package envconf
2021-03-24 10:51:09 +00:00
import ("time")
2021-03-23 13:37:00 +00:00
2021-03-23 11:57:09 +00:00
type DataType int
const (
TypeNone DataType = iota
TypeInt DataType = iota
TypeDuration DataType = iota
TypeString DataType = iota
TypeBool DataType = iota
)
2021-03-23 13:37:00 +00:00
type cValue struct {
intval int64
durval time.Duration
boolval bool
strval string
err error
}
func (dtype DataType) parse(key string, str string)(ret cValue) {
2021-03-24 10:51:09 +00:00
info, ok := tInfo[dtype]
2021-03-23 13:37:00 +00:00
if ok {
2021-03-24 10:51:09 +00:00
return info.parser(key, str)
2021-03-23 13:37:00 +00:00
}
return
}
2021-03-24 10:51:09 +00:00
func (dtype DataType) String()(string) {
info, ok := tInfo[dtype]
if ok {
return info.name
2021-03-23 13:37:00 +00:00
}
2021-03-24 10:51:09 +00:00
return "invalid"
2021-03-23 13:37:00 +00:00
}