package config import ( "errors" "os" ) type TwitterCredentials struct { ClientID, ClientSecret, CallbackURL string } type Config struct { PublicPath string SessionKey string ListenAddr string Twitter TwitterCredentials } 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{ PublicPath: os.Getenv("ELON_PUBLIC_PATH"), SessionKey: sessionKey, ListenAddr: listenAddr, Twitter: TwitterCredentials{ ClientID: os.Getenv("ELON_TWITTER_CLIENT_ID"), ClientSecret: os.Getenv("ELON_TWITTER_CLIENT_SECRET"), CallbackURL: os.Getenv("ELON_TWITTER_CALLBACK_URL"), }, }, nil }