-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
config.go
44 lines (40 loc) · 1.11 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
package main
import (
"fmt"
"os"
"github.com/pelletier/go-toml/v2"
)
type Config struct {
Domain string `toml:"domain"`
DB struct {
Region string `toml:"region"`
Prefix string `toml:"prefix"`
Endpoint string `toml:"endpoint"`
Debug bool `toml:"debug"`
} `toml:"db"`
Storage struct {
Type string `toml:"type"`
FilesBucket string `toml:"files_bucket"`
UploadsBucket string `toml:"uploads_bucket"`
CacheBucket string `toml:"cache_bucket"`
AccessKeyID string `toml:"access_key_id"`
AccessKeySecret string `toml:"access_key_secret"`
CloudflareAccount string `toml:"cloudflare_account"`
Domain string `toml:"domain"`
Region string `toml:"region"`
Endpoint string `toml:"endpoint"`
} `toml:"storage"`
Queue struct {
SQS string `toml:"sqs"`
Region string `toml:"region"`
} `toml:"queue"`
}
func readConfig(path string) (Config, error) {
var cfg Config
raw, err := os.ReadFile(path)
if err != nil {
return cfg, fmt.Errorf("failed to read config: %w", err)
}
err = toml.Unmarshal(raw, &cfg)
return cfg, err
}