mirror of
https://github.com/drakkan/sftpgo.git
synced 2025-12-06 22:30:56 +03:00
allow to set default arguments values from env vars
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/drakkan/sftpgo/logger"
|
||||
@@ -69,3 +70,23 @@ func SetPathPermissions(path string, uid int, gid int) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// GetEnvVar retrieves the value of the environment variable named
|
||||
// by the key. If the variable is present in the environment the it
|
||||
// returns the fallback value
|
||||
func GetEnvVar(key, fallback string) string {
|
||||
if value, ok := os.LookupEnv(key); ok {
|
||||
return value
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
|
||||
// GetEnvVarAsInt retrieves the value of the environment variable named
|
||||
// by the key and returns its value or fallback
|
||||
func GetEnvVarAsInt(key string, fallback int) int {
|
||||
stringValue := GetEnvVar(key, strconv.Itoa(fallback))
|
||||
if value, err := strconv.Atoi(stringValue); err == nil {
|
||||
return value
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user