rough skeleton and basic user authentication
This commit is contained in:
54
util/conf.go
Normal file
54
util/conf.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
)
|
||||
|
||||
func LoadConfig() (*Config, error) {
|
||||
config := Config{}
|
||||
|
||||
err := config.loadEnv()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// other sources?
|
||||
|
||||
config.verify()
|
||||
return &config, nil
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
ClientID string
|
||||
RedirectURI string
|
||||
}
|
||||
|
||||
func (c *Config) loadEnv() error {
|
||||
err := godotenv.Load()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if str, found := os.LookupEnv("CLIENT_ID"); found {
|
||||
c.ClientID = strings.TrimSpace(str)
|
||||
}
|
||||
if str, found := os.LookupEnv("REDIR_URI"); found {
|
||||
c.RedirectURI = strings.TrimSpace(str)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Config) verify() error {
|
||||
if c.ClientID == "" {
|
||||
return errors.New("unable to load a configured Client ID")
|
||||
}
|
||||
if c.RedirectURI == "" {
|
||||
return errors.New("unable to load a configured Redirect URI")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user