44 lines
1.0 KiB
Go
44 lines
1.0 KiB
Go
|
package envconf
|
||
|
import ("strconv"
|
||
|
"fmt"
|
||
|
"errors"
|
||
|
"time")
|
||
|
|
||
|
func parseInt(key string, str string)(ret cValue) {
|
||
|
val, err := strconv.ParseInt(str, 10, 64)
|
||
|
fmt.Println(val)
|
||
|
if err == nil {
|
||
|
ret.intval = val
|
||
|
} else {
|
||
|
ret.err = errors.New(fmt.Sprintf(`Environment variable "%s" is not of type int.`, key))
|
||
|
}
|
||
|
return
|
||
|
}
|
||
|
|
||
|
func parseDuration(key string, str string)(ret cValue) {
|
||
|
val, err := time.ParseDuration(str)
|
||
|
fmt.Println(val)
|
||
|
if err == nil {
|
||
|
ret.durval = val
|
||
|
} else {
|
||
|
ret.err = errors.New(fmt.Sprintf(`Environment variable "%s" is not of type duration.`, key))
|
||
|
}
|
||
|
return
|
||
|
}
|
||
|
|
||
|
func parseBool(key string, str string)(ret cValue) {
|
||
|
val, err := strconv.ParseBool(str)
|
||
|
fmt.Println(val)
|
||
|
if err == nil {
|
||
|
ret.boolval = val
|
||
|
} else {
|
||
|
ret.err = errors.New(fmt.Sprintf(`Environment variable "%s" is not of type bool.`, key))
|
||
|
}
|
||
|
return
|
||
|
}
|
||
|
|
||
|
func parseString(_ string, str string)(ret cValue) {
|
||
|
ret.strval = str
|
||
|
return
|
||
|
}
|