From f7739c65131c47900d53fcbc42730467ad620c9d Mon Sep 17 00:00:00 2001 From: Roy Olav Purser Date: Wed, 24 Mar 2021 15:15:37 +0100 Subject: [PATCH] add directory type --- datatype.go | 1 + envconf.go | 3 +++ parsers.go | 6 ++++++ typeinfo.go | 4 ++++ 4 files changed, 14 insertions(+) diff --git a/datatype.go b/datatype.go index 914d9a2..b68aa9f 100644 --- a/datatype.go +++ b/datatype.go @@ -7,6 +7,7 @@ const ( TypeInt DataType = iota TypeDuration DataType = iota TypeString DataType = iota + TypeDirectory DataType = iota TypeBool DataType = iota ) diff --git a/envconf.go b/envconf.go index d5d9eab..ced8c2d 100644 --- a/envconf.go +++ b/envconf.go @@ -113,6 +113,9 @@ func (c *Config) GetInt(key string)(int64) { } return 0 } +func (c *Config) GetDirectory(key string)(string) { + return c.GetString(key) +} func (c *Config) GetString(key string)(string) { if c.parsed { upper := strings.ToUpper(key) diff --git a/parsers.go b/parsers.go index 7cb5570..3ec51f4 100644 --- a/parsers.go +++ b/parsers.go @@ -2,6 +2,7 @@ package envconf import ("strconv" "fmt" "errors" + "strings" "time") func parseInt(key string, str string)(ret cValue) { @@ -41,3 +42,8 @@ func parseString(_ string, str string)(ret cValue) { ret.strval = str return } + +func parseDirectory(_ string, str string)(ret cValue) { + ret.strval = strings.TrimRight(str, "/") + return +} diff --git a/typeinfo.go b/typeinfo.go index 8ed04c7..0109222 100644 --- a/typeinfo.go +++ b/typeinfo.go @@ -9,20 +9,24 @@ func init() { var intInfo dataTypeInfo var durInfo dataTypeInfo var strInfo dataTypeInfo + var dirInfo dataTypeInfo var boolInfo dataTypeInfo intInfo.name = "int" durInfo.name = "duration" + dirInfo.name = "directory" strInfo.name = "string" boolInfo.name = "bool" intInfo.parser = parseInt durInfo.parser = parseDuration + dirInfo.parser = parseDirectory strInfo.parser = parseString boolInfo.parser = parseBool tInfo[TypeInt] = intInfo tInfo[TypeDuration] = durInfo tInfo[TypeString] = strInfo + tInfo[TypeDirectory] = dirInfo tInfo[TypeBool] = boolInfo }