updated conf
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
CLIENT_ID= # Twitch Client ID
|
CLIENT_ID= # Twitch Client ID
|
||||||
# Required
|
# Required
|
||||||
|
CLIENT_SECRET= # Twitch Client Secret
|
||||||
|
# Required
|
||||||
REDIR_URI= # Twitch OAuth Redirect URI
|
REDIR_URI= # Twitch OAuth Redirect URI
|
||||||
# Required
|
# Required
|
||||||
|
|
||||||
|
|||||||
15
util/conf.go
15
util/conf.go
@@ -10,6 +10,7 @@ import (
|
|||||||
|
|
||||||
func LoadConfig() (*Config, error) {
|
func LoadConfig() (*Config, error) {
|
||||||
config := Config{}
|
config := Config{}
|
||||||
|
config.def()
|
||||||
|
|
||||||
err := config.loadEnv()
|
err := config.loadEnv()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -17,15 +18,15 @@ func LoadConfig() (*Config, error) {
|
|||||||
}
|
}
|
||||||
// other sources?
|
// other sources?
|
||||||
|
|
||||||
config.def()
|
|
||||||
config.verify()
|
config.verify()
|
||||||
return &config, nil
|
return &config, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
ClientID string
|
ClientID string
|
||||||
RedirectURI string
|
ClientSecret string
|
||||||
SQliteDB string
|
RedirectURI string
|
||||||
|
SQliteDB string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) def() {
|
func (c *Config) def() {
|
||||||
@@ -41,6 +42,9 @@ func (c *Config) loadEnv() error {
|
|||||||
if str, found := os.LookupEnv("CLIENT_ID"); found {
|
if str, found := os.LookupEnv("CLIENT_ID"); found {
|
||||||
c.ClientID = strings.TrimSpace(str)
|
c.ClientID = strings.TrimSpace(str)
|
||||||
}
|
}
|
||||||
|
if str, found := os.LookupEnv("CLIENT_SECRET"); found {
|
||||||
|
c.ClientSecret = strings.TrimSpace(str)
|
||||||
|
}
|
||||||
if str, found := os.LookupEnv("REDIR_URI"); found {
|
if str, found := os.LookupEnv("REDIR_URI"); found {
|
||||||
c.RedirectURI = strings.TrimSpace(str)
|
c.RedirectURI = strings.TrimSpace(str)
|
||||||
}
|
}
|
||||||
@@ -55,6 +59,9 @@ func (c *Config) verify() error {
|
|||||||
if c.ClientID == "" {
|
if c.ClientID == "" {
|
||||||
return errors.New("unable to load a configured Client ID")
|
return errors.New("unable to load a configured Client ID")
|
||||||
}
|
}
|
||||||
|
if c.ClientSecret == "" {
|
||||||
|
return errors.New("unable to load a configured Client Secret")
|
||||||
|
}
|
||||||
if c.RedirectURI == "" {
|
if c.RedirectURI == "" {
|
||||||
return errors.New("unable to load a configured Redirect URI")
|
return errors.New("unable to load a configured Redirect URI")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user