2022-05-19 19:51:12 +00:00
|
|
|
package config
|
|
|
|
|
2022-05-20 00:26:42 +00:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"os"
|
|
|
|
)
|
2022-05-19 19:51:12 +00:00
|
|
|
|
2022-05-20 19:52:54 +00:00
|
|
|
type TwitterConfig struct {
|
|
|
|
ClientID, ClientSecret, CallbackURL, AuthorizeURL, TokenURL string
|
2022-05-19 19:51:12 +00:00
|
|
|
}
|
|
|
|
type Config struct {
|
2022-05-20 20:57:45 +00:00
|
|
|
DatabaseURL string
|
|
|
|
SessionKey string
|
|
|
|
ListenAddr string
|
|
|
|
Twitter TwitterConfig
|
2022-05-19 19:51:12 +00:00
|
|
|
}
|
|
|
|
|
2022-05-20 00:26:42 +00:00
|
|
|
func NewFromEnv() (Config, error) {
|
2022-05-19 23:03:11 +00:00
|
|
|
listenAddr := os.Getenv("ELON_LISTEN_ADDR")
|
|
|
|
if listenAddr == "" {
|
|
|
|
listenAddr = ":8000"
|
|
|
|
}
|
2022-05-20 00:26:42 +00:00
|
|
|
sessionKey := os.Getenv("ELON_SESSION_KEY")
|
|
|
|
if sessionKey == "" {
|
|
|
|
return Config{}, errors.New("missing ELON_SESSION_KEY")
|
|
|
|
}
|
2022-05-19 19:51:12 +00:00
|
|
|
return Config{
|
2022-05-20 20:57:45 +00:00
|
|
|
DatabaseURL: os.Getenv("ELON_DATABASE_URL"),
|
|
|
|
SessionKey: sessionKey,
|
|
|
|
ListenAddr: listenAddr,
|
2022-05-20 19:52:54 +00:00
|
|
|
Twitter: TwitterConfig{
|
2022-05-19 19:51:12 +00:00
|
|
|
ClientID: os.Getenv("ELON_TWITTER_CLIENT_ID"),
|
|
|
|
ClientSecret: os.Getenv("ELON_TWITTER_CLIENT_SECRET"),
|
|
|
|
CallbackURL: os.Getenv("ELON_TWITTER_CALLBACK_URL"),
|
2022-05-20 19:52:54 +00:00
|
|
|
AuthorizeURL: os.Getenv("ELON_TWITTER_AUTHORIZE_URL"),
|
|
|
|
TokenURL: os.Getenv("ELON_TWITTER_TOKEN_URL"),
|
2022-05-19 19:51:12 +00:00
|
|
|
},
|
2022-05-20 00:26:42 +00:00
|
|
|
}, nil
|
2022-05-19 19:51:12 +00:00
|
|
|
}
|