2024-12-18 18:54:48 +00:00
|
|
|
package env
|
|
|
|
|
|
|
|
|
|
import (
|
2024-12-19 18:49:22 +00:00
|
|
|
"fmt"
|
2024-12-18 18:54:48 +00:00
|
|
|
"log"
|
|
|
|
|
"os"
|
|
|
|
|
)
|
|
|
|
|
|
2024-12-24 18:11:25 +00:00
|
|
|
func GetPanic(name string) string {
|
2024-12-19 18:49:22 +00:00
|
|
|
value, err := Get(name)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Panic(err.Error())
|
2024-12-18 18:54:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return value
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-19 18:49:22 +00:00
|
|
|
func Get(name string) (string, error) {
|
2024-12-18 18:54:48 +00:00
|
|
|
value, exists := os.LookupEnv(name)
|
2024-12-19 18:49:22 +00:00
|
|
|
if !exists || value == "" {
|
|
|
|
|
return "", fmt.Errorf("environment variable not set: %s", name)
|
2024-12-18 18:54:48 +00:00
|
|
|
}
|
|
|
|
|
|
2024-12-19 18:49:22 +00:00
|
|
|
return value, nil
|
2024-12-18 18:54:48 +00:00
|
|
|
}
|