-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.go
More file actions
55 lines (49 loc) · 1.45 KB
/
config.go
File metadata and controls
55 lines (49 loc) · 1.45 KB
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
55
package main
import (
"bufio"
"fmt"
"os"
"time"
"github.com/PaoDevelopers/go-scfgs"
)
type Config struct {
Database struct {
URL string `scfgs:"url"`
MaxConns int32 `scfgs:"max_conns"`
MinConns int32 `scfgs:"min_conns"`
MaxConnLifetime time.Duration `scfgs:"max_conn_lifetime"`
MaxConnIdleTime time.Duration `scfgs:"max_conn_idle_time"`
HealthCheckPeriod time.Duration `scfgs:"health_check_period"`
ConnectTimeout time.Duration `scfgs:"connect_timeout"`
} `scfgs:"database"`
Listen struct {
Protocol string `scfgs:"protocol"`
Network string `scfgs:"network"`
Address string `scfgs:"address"`
Transport string `scfgs:"transport"`
TLS struct {
Cert string `scfgs:"cert"`
Key string `scfgs:"key"`
} `scfgs:"tls"`
} `scfgs:"listen"`
OIDC struct {
Bypass bool `scfgs:"bypass"`
Client string `scfgs:"client"`
Authorize string `scfgs:"authorize"`
JWKS string `scfgs:"jwks"`
} `scfgs:"oidc"`
Admins map[string]struct{} `scfgs:"admins"`
// SSEBuf int `scfgs:"sse_buf"` // Not needed anymore
}
func loadConfig(path string) (Config, error) {
f, err := os.Open(path) //#nosec G304
if err != nil {
return Config{}, fmt.Errorf("open config: %w", err)
}
var config Config
err = scfgs.NewDecoder(bufio.NewReader(f)).Decode(&config)
if err != nil {
return config, fmt.Errorf("decode config: %w", err)
}
return config, nil
}