orama/invest-api/config/config.go
anonpenguin23 655bd92178 Squashed 'website/' content from commit d19b985
git-subtree-dir: website
git-subtree-split: d19b98589ec5d235560a210b26195b653a65a808
2026-03-26 18:14:59 +02:00

51 lines
1.0 KiB
Go

package config
import (
"fmt"
"os"
"github.com/joho/godotenv"
)
type Config struct {
Port string
DBPath string
JWTSecret string
HeliusAPIKey string
HeliusRPCURL string
}
func Load() (*Config, error) {
// Load .env file if it exists (ignore error if missing)
_ = godotenv.Load()
cfg := &Config{
Port: envOrDefault("PORT", "8090"),
DBPath: envOrDefault("DB_PATH", "invest.db"),
JWTSecret: os.Getenv("JWT_SECRET"),
HeliusAPIKey: os.Getenv("HELIUS_API_KEY"),
HeliusRPCURL: os.Getenv("HELIUS_RPC_URL"),
}
if cfg.JWTSecret == "" {
return nil, fmt.Errorf("JWT_SECRET environment variable is required")
}
if cfg.HeliusAPIKey == "" {
return nil, fmt.Errorf("HELIUS_API_KEY environment variable is required")
}
if cfg.HeliusRPCURL == "" {
cfg.HeliusRPCURL = "https://mainnet.helius-rpc.com/?api-key=" + cfg.HeliusAPIKey
}
return cfg, nil
}
func envOrDefault(key, fallback string) string {
if v := os.Getenv(key); v != "" {
return v
}
return fallback
}