setup config loading

This commit is contained in:
juancwu 2026-01-21 18:11:28 +00:00
commit f9c8ed4f6c
6 changed files with 52 additions and 12 deletions

33
internal/config/config.go Normal file
View file

@ -0,0 +1,33 @@
package config
import (
"fmt"
"os"
"github.com/joho/godotenv"
)
type Config struct {
PorkbunApiKeyName string
PorkbunSecretApiKeyName string
}
func Load() *Config {
godotenv.Load()
cfg := &Config{
PorkbunApiKeyName: envRequired("PORKBUN_API_KEY_NAME"),
PorkbunSecretApiKeyName: envRequired("PORKBUN_SECRET_API_KEY_NAME"),
}
return cfg
}
func envRequired(key string) string {
value, ok := os.LookupEnv(key)
if !ok || value == "" {
fmt.Printf("Error: required environment variable %s not set.\n", key)
os.Exit(1)
}
return value
}