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

42 lines
1017 B
Go
Raw Normal View History

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 {
PublicPath string
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{
PublicPath: os.Getenv("ELON_PUBLIC_PATH"),
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
}