2021-03-23 11:57:09 +00:00
|
|
|
package envconf
|
2021-03-26 16:17:52 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
)
|
2021-03-23 13:37:00 +00:00
|
|
|
|
2021-03-23 11:57:09 +00:00
|
|
|
type DataType int
|
2021-03-26 16:17:52 +00:00
|
|
|
|
2021-03-23 11:57:09 +00:00
|
|
|
const (
|
2021-03-26 16:17:52 +00:00
|
|
|
TypeNone DataType = iota
|
|
|
|
TypeInt DataType = iota
|
|
|
|
TypeMetric DataType = iota
|
|
|
|
TypeDuration DataType = iota
|
|
|
|
TypeString DataType = iota
|
|
|
|
TypeDirectory DataType = iota
|
|
|
|
TypeBool DataType = iota
|
2021-03-23 11:57:09 +00:00
|
|
|
)
|
|
|
|
|
2021-03-23 13:37:00 +00:00
|
|
|
type cValue struct {
|
2021-03-26 16:17:52 +00:00
|
|
|
dtype DataType
|
|
|
|
intval int64
|
|
|
|
durval time.Duration
|
|
|
|
boolval bool
|
|
|
|
strval string
|
2022-01-15 16:55:29 +00:00
|
|
|
mapval map[string]cValue
|
2021-03-26 16:17:52 +00:00
|
|
|
err error
|
2021-03-23 13:37:00 +00:00
|
|
|
}
|
|
|
|
|
2021-03-26 16:17:52 +00:00
|
|
|
func (dtype DataType) parse(key string, str string) (ret cValue) {
|
|
|
|
info, ok := tInfo[dtype]
|
|
|
|
if ok {
|
|
|
|
return info.parser(key, str)
|
|
|
|
}
|
|
|
|
return
|
2021-03-23 13:37:00 +00:00
|
|
|
}
|
2021-03-26 16:17:52 +00:00
|
|
|
func (dtype DataType) String() string {
|
|
|
|
info, ok := tInfo[dtype]
|
|
|
|
if ok {
|
|
|
|
return info.name
|
|
|
|
}
|
|
|
|
return "invalid"
|
2021-03-23 13:37:00 +00:00
|
|
|
}
|