36 lines
660 B
Go
36 lines
660 B
Go
package envconf
|
|
import ("time")
|
|
|
|
type DataType int
|
|
const (
|
|
TypeNone DataType = iota
|
|
TypeInt DataType = iota
|
|
TypeDuration DataType = iota
|
|
TypeString DataType = iota
|
|
TypeDirectory DataType = iota
|
|
TypeBool DataType = iota
|
|
)
|
|
|
|
type cValue struct {
|
|
intval int64
|
|
durval time.Duration
|
|
boolval bool
|
|
strval string
|
|
err error
|
|
}
|
|
|
|
func (dtype DataType) parse(key string, str string)(ret cValue) {
|
|
info, ok := tInfo[dtype]
|
|
if ok {
|
|
return info.parser(key, str)
|
|
}
|
|
return
|
|
}
|
|
func (dtype DataType) String()(string) {
|
|
info, ok := tInfo[dtype]
|
|
if ok {
|
|
return info.name
|
|
}
|
|
return "invalid"
|
|
}
|