rough skeleton and basic user authentication

This commit is contained in:
zomo
2025-10-31 10:32:50 -05:00
commit 8355ca374b
17 changed files with 542 additions and 0 deletions

54
util/conf.go Normal file
View 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
}