0
0
mirror of https://github.com/bpg/terraform-provider-proxmox.git synced 2025-06-29 18:21:10 +00:00
terraform-provider-proxmox/utils/env.go
Pavel Boldyrev 268c861649
chore: improve acceptance tests on CI (#1173)
Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>
2024-04-07 04:41:57 +00:00

51 lines
1021 B
Go

/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package utils
import (
"os"
"strconv"
)
// GetAnyStringEnv returns the first non-empty string value from the environment variables.
func GetAnyStringEnv(ks ...string) string {
for _, k := range ks {
if v := os.Getenv(k); v != "" {
return v
}
}
return ""
}
// GetAnyBoolEnv returns the first non-empty boolean value from the environment variables.
func GetAnyBoolEnv(ks ...string) bool {
val := ""
for _, k := range ks {
if v := os.Getenv(k); v != "" {
val = v
break
}
}
return val == "true" || val == "1"
}
// GetAnyIntEnv returns the first non-empty integer value from the environment variables.
func GetAnyIntEnv(ks ...string) int {
for _, k := range ks {
if v := os.Getenv(k); v != "" {
if i, err := strconv.Atoi(v); err == nil {
return i
}
}
}
return 0
}