setup config loading
This commit is contained in:
parent
a44c3756c7
commit
f9c8ed4f6c
6 changed files with 52 additions and 12 deletions
|
|
@ -1,14 +1,16 @@
|
|||
package app
|
||||
|
||||
import (
|
||||
"git.juancwu.dev/juancwu/porkbacon/internal/config"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
cfg *config.Config
|
||||
}
|
||||
|
||||
func New() App {
|
||||
return App{}
|
||||
func New(cfg *config.Config) App {
|
||||
return App{cfg: cfg}
|
||||
}
|
||||
|
||||
func (a App) Init() tea.Cmd {
|
||||
|
|
|
|||
33
internal/config/config.go
Normal file
33
internal/config/config.go
Normal 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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue