opportunistic absolute file path
This commit is contained in:
parent
38306fd9a3
commit
108cd021d1
15
parsers.go
15
parsers.go
@ -2,7 +2,8 @@ package envconf
|
|||||||
import ("strconv"
|
import ("strconv"
|
||||||
"fmt"
|
"fmt"
|
||||||
"errors"
|
"errors"
|
||||||
"path/filepath"
|
"os"
|
||||||
|
"path"
|
||||||
"time")
|
"time")
|
||||||
|
|
||||||
func parseInt(key string, str string)(ret cValue) {
|
func parseInt(key string, str string)(ret cValue) {
|
||||||
@ -35,12 +36,16 @@ func parseBool(key string, str string)(ret cValue) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseDirectory(key string, str string)(ret cValue) {
|
func parseDirectory(_ string, str string)(ret cValue) {
|
||||||
val, err := filepath.Abs(str)
|
wd, err := os.Getwd()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
ret.strval = val
|
if path.IsAbs(str) {
|
||||||
|
ret.strval = path.Clean(str)
|
||||||
} else {
|
} else {
|
||||||
ret.err = errors.New(fmt.Sprintf(`Environment variable "%s" is not of type directory.`, key))
|
ret.strval = path.Join(wd, str)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ret.strval = path.Clean(str)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user