add directory type
This commit is contained in:
parent
a8afecff3b
commit
f7739c6513
@ -7,6 +7,7 @@ const (
|
|||||||
TypeInt DataType = iota
|
TypeInt DataType = iota
|
||||||
TypeDuration DataType = iota
|
TypeDuration DataType = iota
|
||||||
TypeString DataType = iota
|
TypeString DataType = iota
|
||||||
|
TypeDirectory DataType = iota
|
||||||
TypeBool DataType = iota
|
TypeBool DataType = iota
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -113,6 +113,9 @@ func (c *Config) GetInt(key string)(int64) {
|
|||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
func (c *Config) GetDirectory(key string)(string) {
|
||||||
|
return c.GetString(key)
|
||||||
|
}
|
||||||
func (c *Config) GetString(key string)(string) {
|
func (c *Config) GetString(key string)(string) {
|
||||||
if c.parsed {
|
if c.parsed {
|
||||||
upper := strings.ToUpper(key)
|
upper := strings.ToUpper(key)
|
||||||
|
@ -2,6 +2,7 @@ package envconf
|
|||||||
import ("strconv"
|
import ("strconv"
|
||||||
"fmt"
|
"fmt"
|
||||||
"errors"
|
"errors"
|
||||||
|
"strings"
|
||||||
"time")
|
"time")
|
||||||
|
|
||||||
func parseInt(key string, str string)(ret cValue) {
|
func parseInt(key string, str string)(ret cValue) {
|
||||||
@ -41,3 +42,8 @@ func parseString(_ string, str string)(ret cValue) {
|
|||||||
ret.strval = str
|
ret.strval = str
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func parseDirectory(_ string, str string)(ret cValue) {
|
||||||
|
ret.strval = strings.TrimRight(str, "/")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
@ -9,20 +9,24 @@ func init() {
|
|||||||
var intInfo dataTypeInfo
|
var intInfo dataTypeInfo
|
||||||
var durInfo dataTypeInfo
|
var durInfo dataTypeInfo
|
||||||
var strInfo dataTypeInfo
|
var strInfo dataTypeInfo
|
||||||
|
var dirInfo dataTypeInfo
|
||||||
var boolInfo dataTypeInfo
|
var boolInfo dataTypeInfo
|
||||||
|
|
||||||
intInfo.name = "int"
|
intInfo.name = "int"
|
||||||
durInfo.name = "duration"
|
durInfo.name = "duration"
|
||||||
|
dirInfo.name = "directory"
|
||||||
strInfo.name = "string"
|
strInfo.name = "string"
|
||||||
boolInfo.name = "bool"
|
boolInfo.name = "bool"
|
||||||
|
|
||||||
intInfo.parser = parseInt
|
intInfo.parser = parseInt
|
||||||
durInfo.parser = parseDuration
|
durInfo.parser = parseDuration
|
||||||
|
dirInfo.parser = parseDirectory
|
||||||
strInfo.parser = parseString
|
strInfo.parser = parseString
|
||||||
boolInfo.parser = parseBool
|
boolInfo.parser = parseBool
|
||||||
|
|
||||||
tInfo[TypeInt] = intInfo
|
tInfo[TypeInt] = intInfo
|
||||||
tInfo[TypeDuration] = durInfo
|
tInfo[TypeDuration] = durInfo
|
||||||
tInfo[TypeString] = strInfo
|
tInfo[TypeString] = strInfo
|
||||||
|
tInfo[TypeDirectory] = dirInfo
|
||||||
tInfo[TypeBool] = boolInfo
|
tInfo[TypeBool] = boolInfo
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user