package config import ( "errors" "os" ) type TwitterConfig struct { ClientID, ClientSecret, CallbackURL, AuthorizeURL, TokenURL string } type Config struct { DatabaseURL string SessionKey string ListenAddr string Twitter TwitterConfig } func NewFromEnv() (Config, error) { listenAddr := os.Getenv("ELON_LISTEN_ADDR") if listenAddr == "" { listenAddr = ":8000" } sessionKey := os.Getenv("ELON_SESSION_KEY") if sessionKey == "" { return Config{}, errors.New("missing ELON_SESSION_KEY") } return Config{ DatabaseURL: os.Getenv("ELON_DATABASE_URL"), SessionKey: sessionKey, ListenAddr: listenAddr, Twitter: TwitterConfig{ ClientID: os.Getenv("ELON_TWITTER_CLIENT_ID"), ClientSecret: os.Getenv("ELON_TWITTER_CLIENT_SECRET"), CallbackURL: os.Getenv("ELON_TWITTER_CALLBACK_URL"), AuthorizeURL: os.Getenv("ELON_TWITTER_AUTHORIZE_URL"), TokenURL: os.Getenv("ELON_TWITTER_TOKEN_URL"), }, }, nil }