diff options
Diffstat (limited to 'sd_login/util.go')
-rw-r--r-- | sd_login/util.go | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/sd_login/util.go b/sd_login/util.go index 45df0e0..2497aef 100644 --- a/sd_login/util.go +++ b/sd_login/util.go @@ -1,4 +1,4 @@ -// Copyright (C) 2016 Luke Shumaker <lukeshu@sbcglobal.net> +// Copyright (C) 2016-2017 Luke Shumaker <lukeshu@sbcglobal.net> // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -19,6 +19,8 @@ import ( "os" "path" "strings" + + "golang.org/x/sys/unix" ) const ( @@ -97,6 +99,27 @@ func get_files_in_directory(apath string) ([]string, error) { return ret, nil } +func parse_boolean(v string) (bool, error) { + switch { + case v == "1", + strings.EqualFold(v, "yes"), + strings.EqualFold(v, "y"), + strings.EqualFold(v, "true"), + strings.EqualFold(v, "t"), + strings.EqualFold(v, "on"): + return true, nil + case v == "0", + strings.EqualFold(v, "no"), + strings.EqualFold(v, "n"), + strings.EqualFold(v, "false"), + strings.EqualFold(v, "f"), + strings.EqualFold(v, "off"): + return false, nil + default: + return false, unix.EINVAL + } +} + func parse_env_file(filename string) (map[string]string, error) /* |