remove the need to setup .env and ask for porkbun credential name directly
This commit is contained in:
parent
f9c8ed4f6c
commit
ec94e6ad46
7 changed files with 164 additions and 47 deletions
|
|
@ -1,33 +0,0 @@
|
|||
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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue