config/config.go (view raw)
1package config
2
3import (
4 "fmt"
5 "os"
6
7 "gopkg.in/yaml.v3"
8)
9
10type Config struct {
11 Repo struct {
12 ScanPath string `yaml:"scanPath"`
13 Readme []string `yaml:"readme"`
14 MainBranch []string `yaml:"mainBranch"`
15 } `yaml:"repo"`
16 Dirs struct {
17 Templates string `yaml:"templates"`
18 Static string `yaml:"static"`
19 } `yaml:"dirs"`
20 Meta struct {
21 Title string `yaml:"title"`
22 Description string `yaml:"description"`
23 } `yaml:"meta"`
24 Misc struct {
25 GoImport struct {
26 PrettyURL string `yaml:"string"`
27 } `yaml:"goImport"`
28 } `yaml:"misc"`
29 Server struct {
30 FQDN string `yaml:"fqdn,omitempty"`
31 Host string `yaml:"host"`
32 Port int `yaml:"port"`
33 } `yaml:"server"`
34}
35
36func Read(f string) (*Config, error) {
37 b, err := os.ReadFile(f)
38 if err != nil {
39 return nil, fmt.Errorf("reading config: %w", err)
40 }
41
42 c := Config{}
43 if err := yaml.Unmarshal(b, &c); err != nil {
44 return nil, fmt.Errorf("parsing config: %w", err)
45 }
46
47 return &c, nil
48}