envconf/datatype.go
2022-01-16 21:48:29 +01:00

51 lines
909 B
Go

package envconf
import (
"time"
)
type DataType int
const (
TypeNone DataType = iota
TypeInt DataType = iota
TypeMetric DataType = iota
TypeDuration DataType = iota
TypeString DataType = iota
TypeDirectory DataType = iota
TypeBool DataType = iota
TypeHex DataType = iota
TypeHex16 DataType = iota
TypeHex32 DataType = iota
TypeHex64 DataType = iota
TypeHex128 DataType = iota
)
type cValue struct {
dtype DataType
intval int64
durval time.Duration
boolval bool
binval []byte
strval string
err error
}
func (dtype DataType) parse(key string, str string) (ret cValue) {
info, ok := tInfo[dtype]
if ok {
ret = info.parser(key, str)
if len(ret.binval) == 0 {
ret.binval = make([]byte, 0, 0)
}
}
return
}
func (dtype DataType) String() string {
info, ok := tInfo[dtype]
if ok {
return info.name
}
return "invalid"
}