-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
54 lines (45 loc) · 1.16 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
44
45
46
47
48
49
50
51
52
53
54
package config
import (
_ "embed"
"fmt"
"log"
"gopkg.in/yaml.v3"
)
//go:embed config-local.yml
var configData []byte
type Config struct {
Postgres PostgresConfig `yaml:"postgres"`
DefaultUser DefaultUserConfig `yaml:"defaultuser"`
Login LoginConfig `yaml:"login"`
Server ServerConfig `yaml:"server"`
}
func NewConfig() *Config {
// Parse the YAML data
var conf Config
if err := yaml.Unmarshal(configData, &conf); err != nil {
log.Fatal(err)
}
fmt.Println(conf.Postgres.Host)
return &conf
}
type PostgresConfig struct {
Host string `yaml:"host"`
Port int `yaml:"port"`
User string `yaml:"user"`
Password string `yaml:"password"`
Database string `yaml:"database"`
}
// DefaultUserConfig a default admin user which will be created during database
// initialization stage when the service startsup for the first time.
// We recommend changing the password asap
type DefaultUserConfig struct {
Username string `yaml:"username"`
Password string `yaml:"password"`
}
type LoginConfig struct {
Expiry int `yaml:"expiry"` // in minutes
Secret string `yaml:"secret"`
}
type ServerConfig struct {
Port int `yaml:"port"`
}