envconf/typeinfo.go

40 lines
871 B
Go
Raw Normal View History

2021-03-24 10:51:09 +00:00
package envconf
2021-03-26 16:17:52 +00:00
2021-03-24 10:51:09 +00:00
type dataTypeInfo struct {
2021-03-26 16:17:52 +00:00
parser func(string, string) cValue
name string
2021-03-24 10:51:09 +00:00
}
2021-03-26 16:17:52 +00:00
2021-03-24 10:51:09 +00:00
var tInfo map[DataType]dataTypeInfo
2021-03-26 16:17:52 +00:00
2021-03-24 10:51:09 +00:00
func init() {
2021-03-26 16:17:52 +00:00
tInfo = make(map[DataType]dataTypeInfo)
var intInfo dataTypeInfo
var metricInfo dataTypeInfo
var durInfo dataTypeInfo
var strInfo dataTypeInfo
var dirInfo dataTypeInfo
var boolInfo dataTypeInfo
2021-03-24 10:51:09 +00:00
2021-03-26 16:17:52 +00:00
intInfo.name = "int"
metricInfo.name = "metric"
durInfo.name = "duration"
dirInfo.name = "directory"
strInfo.name = "string"
boolInfo.name = "bool"
2021-03-24 10:51:09 +00:00
2021-03-26 16:17:52 +00:00
intInfo.parser = parseInt
metricInfo.parser = parseMetric
durInfo.parser = parseDuration
dirInfo.parser = parseDirectory
strInfo.parser = parseString
boolInfo.parser = parseBool
2021-03-24 10:51:09 +00:00
2021-03-26 16:17:52 +00:00
tInfo[TypeInt] = intInfo
tInfo[TypeMetric] = metricInfo
tInfo[TypeDuration] = durInfo
tInfo[TypeString] = strInfo
tInfo[TypeDirectory] = dirInfo
tInfo[TypeBool] = boolInfo
2021-03-24 10:51:09 +00:00
}