naco-api/internal/config/config.go
Nacorid 2ae53d8dc5
add: supported network config option
update: align testClient with x402-v2
2026-08-03 12:40:04 +00:00

69 lines
2.2 KiB
Go

package config
import (
"os"
"strconv"
"github.com/joho/godotenv"
log "github.com/nacorid/logger"
)
type Config struct {
ListenAddress string
ListenPort string
UnixSocketPath string
UnixSocketPermissions os.FileMode
DatabaseURL string
ActivityPubHost string
ActivityPubToken string
BlueskyDID string
BlueskyAppPassword string
BlueskyHost string
OllamaHost string
X402FacilitatorURL string
X402WalletAddress string
ApiKey string
ApiSecret string
LogFile string
ActiveNetworks string
}
func Load() *Config {
if err := godotenv.Load(); err != nil {
log.Debug("No .env file found, reading from environment")
}
permsStr := getEnv("UNIX_SOCKET_PERMISSIONS", "0660")
perms, err := strconv.ParseUint(permsStr, 8, 32)
if err != nil {
log.Fatal("Invalid UNIX_SOCKET_PERMISSIONS", "error", err)
}
return &Config{
ListenAddress: getEnv("SERVER_ADDRESS", "127.0.0.1"),
ListenPort: getEnv("SERVER_PORT", "8080"),
UnixSocketPermissions: os.FileMode(perms),
DatabaseURL: getEnv("GOOSE_DBSTRING", "postgres:///mcpserver"),
ActivityPubHost: getEnv("AP_HOST", "https://mastodon.social"),
ActivityPubToken: getEnv("AP_ACCESS_TOKEN", ""),
BlueskyDID: getEnv("BLUESKY_DID", ""),
BlueskyAppPassword: getEnv("BLUESKY_APP_PASSWORD", ""),
BlueskyHost: getEnv("BLUESKY_HOST", "https://bsky.social"),
OllamaHost: getEnv("OLLAMA_HOST", "http://localhost:11434"),
X402FacilitatorURL: getEnv("X402_FACILITATOR_URL", "https://facilitator.x402.rs"),
X402WalletAddress: getEnv("X402_WALLET_ADDRESS", ""),
ApiKey: getEnv("CDP_API_KEY_ID", ""),
ApiSecret: getEnv("CDP_API_SECRET", ""),
LogFile: getEnv("LOG_FILE", "/var/log/mcpserver/output.log"),
ActiveNetworks: getEnv("ACTIVE_NETWORKS", "base"),
}
}
func getEnv(key, fallback string) string {
if value, ok := os.LookupEnv(key); ok {
return value
}
if fallback == "" {
log.Fatal("Environment variable is not set", "key", key)
}
return fallback
}