This repository has been archived on 2022-05-25. You can view files and clone it, but cannot push or open issues or pull requests.
elon-eats-my-tweets/config/config.go

38 lines
822 B
Go

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
}