-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
43 lines (32 loc) · 1.03 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package grackdb
import (
"fmt"
"os"
"github.com/joho/godotenv"
"github.com/kelseyhightower/envconfig"
)
type Config struct {
DBConnectionString string `default:"file:grack.db?_fk=1" split_words:"true"`
BindAddr string `default:":8081" split_words:"true"`
JwtSigningSecret string `default:"grack" split_words:"true"`
GithubClientId string `default:"" split_words:"true"`
GithubClientSecret string `default:"" split_words:"true"`
DiscordClientId string `default:"" split_words:"true"`
DiscordClientSecret string `default:"" split_words:"true"`
DiscordCallbackUrl string `default:"http://localhost:8081/oauth/discord/callback" split_words:"true"`
DevelopmentMode bool `default:"false" split_words:"true"`
}
var AppConfig Config
func LoadConfig() error {
envfile, ok := os.LookupEnv("GRACKDB_DOTENV_PATH")
if ok {
godotenv.Load(envfile)
} else {
godotenv.Load(".env")
}
err := envconfig.Process("grackdb", &AppConfig)
if err != nil {
return fmt.Errorf("error loading config: %w", err)
}
return nil
}