2021-03-24 10:51:09 +00:00
|
|
|
package envconf
|
|
|
|
import ("strconv"
|
|
|
|
"fmt"
|
|
|
|
"errors"
|
2021-03-25 08:55:14 +00:00
|
|
|
"path/filepath"
|
2021-03-24 10:51:09 +00:00
|
|
|
"time")
|
|
|
|
|
|
|
|
func parseInt(key string, str string)(ret cValue) {
|
|
|
|
val, err := strconv.ParseInt(str, 10, 64)
|
|
|
|
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)
|
|
|
|
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)
|
|
|
|
if err == nil {
|
|
|
|
ret.boolval = val
|
|
|
|
} else {
|
|
|
|
ret.err = errors.New(fmt.Sprintf(`Environment variable "%s" is not of type bool.`, key))
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-03-25 08:55:14 +00:00
|
|
|
func parseDirectory(key string, str string)(ret cValue) {
|
|
|
|
val, err := filepath.Abs(str)
|
|
|
|
if err == nil {
|
|
|
|
ret.strval = val
|
|
|
|
} else {
|
|
|
|
ret.err = errors.New(fmt.Sprintf(`Environment variable "%s" is not of type directory.`, key))
|
|
|
|
}
|
2021-03-24 10:51:09 +00:00
|
|
|
return
|
|
|
|
}
|
2021-03-24 14:15:37 +00:00
|
|
|
|
2021-03-25 08:55:14 +00:00
|
|
|
func parseString(_ string, str string)(ret cValue) {
|
|
|
|
ret.strval = str
|
2021-03-24 14:15:37 +00:00
|
|
|
return
|
|
|
|
}
|
2021-03-25 08:55:14 +00:00
|
|
|
|