blob: 414a81113c53e3bc5eb1c58d47a26dab4892f43b (
plain) (
blame)
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
package config
import (
"bufio"
"fmt"
"log/slog"
"os"
"go.lindenii.runxiyu.org/forge/forged/internal/common/scfg"
)
type Config struct {
DB DB `scfgs:"db"`
Web Web `scfgs:"web"`
Hooks Hooks `scfgs:"hooks"`
LMTP LMTP `scfgs:"lmtp"`
SSH SSH `scfgs:"ssh"`
IRC IRC `scfgs:"irc"`
Git Git `scfgs:"git"`
General General `scfgs:"general"`
Pprof Pprof `scfgs:"pprof"`
}
type DB struct {
Conn string `scfgs:"conn"`
}
type Web struct {
Net string `scfgs:"net"`
Addr string `scfgs:"addr"`
Root string `scfgs:"root"`
CookieExpiry int `scfgs:"cookie_expiry"`
ReadTimeout uint32 `scfgs:"read_timeout"`
WriteTimeout uint32 `scfgs:"write_timeout"`
IdleTimeout uint32 `scfgs:"idle_timeout"`
MaxHeaderBytes int `scfgs:"max_header_bytes"`
ReverseProxy bool `scfgs:"reverse_proxy"`
ShutdownTimeout uint32 `scfgs:"shutdown_timeout"`
TemplatesPath string `scfgs:"templates_path"`
StaticPath string `scfgs:"static_path"`
}
type Hooks struct {
Socket string `scfgs:"socket"`
Execs string `scfgs:"execs"`
}
type LMTP struct {
Socket string `scfgs:"socket"`
Domain string `scfgs:"domain"`
MaxSize int64 `scfgs:"max_size"`
WriteTimeout uint32 `scfgs:"write_timeout"`
ReadTimeout uint32 `scfgs:"read_timeout"`
}
type SSH struct {
Net string `scfgs:"net"`
Addr string `scfgs:"addr"`
Key string `scfgs:"key"`
Root string `scfgs:"root"`
ShutdownTimeout uint32 `scfgs:"shutdown_timeout"`
}
type IRC struct {
Net string `scfgs:"net"`
Addr string `scfgs:"addr"`
TLS bool `scfgs:"tls"`
SendQ uint `scfgs:"sendq"`
Nick string `scfgs:"nick"`
User string `scfgs:"user"`
Gecos string `scfgs:"gecos"`
}
type Git struct {
RepoDir string `scfgs:"repo_dir"`
Socket string `scfgs:"socket"`
}
type General struct {
Title string `scfgs:"title"`
}
type Pprof struct {
Net string `scfgs:"net"`
Addr string `scfgs:"addr"`
}
func Open(path string) (config Config, err error) {
var configFile *os.File
configFile, err = os.Open(path) //#nosec G304
if err != nil {
err = fmt.Errorf("open config file: %w", err)
return config, err
}
defer func() {
_ = configFile.Close()
}()
decoder := scfgs.NewDecoder(bufio.NewReader(configFile))
err = decoder.Decode(&config)
if err != nil {
err = fmt.Errorf("decode config file: %w", err)
return config, err
}
for _, u := range decoder.UnknownDirectives() {
slog.Warn("unknown configuration directive", "directive", u)
}
return config, err
}
|