envconf/datatype.go

38 lines
710 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
2021-03-25 11:06:08 +00:00
TypeMetric DataType = iota
2021-03-23 11:57:09 +00:00
TypeDuration DataType = iota
TypeString DataType = iota
2021-03-24 14:15:37 +00:00
TypeDirectory DataType = iota
2021-03-23 11:57:09 +00:00
TypeBool DataType = iota
)
2021-03-23 13:37:00 +00:00
type cValue struct {
2021-03-25 13:18:26 +00:00
dtype DataType
2021-03-23 13:37:00 +00:00
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
}