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 Git struct {
12 ScanPath string `yaml:"scanPath"`
13 Readme []string `yaml:"readme"`
14 } `yaml:"git"`
15 Template struct {
16 Dir string `yaml:"dir"`
17 } `yaml:"template"`
18 Meta struct {
19 Title string `yaml:"title"`
20 Description string `yaml:"description"`
21 } `yaml:"meta"`
22 Server struct {
23 Host string `yaml:"host"`
24 Port int `yaml:"port"`
25 } `yaml:"server"`
26}
27
28func Read(f string) (*Config, error) {
29 b, err := os.ReadFile(f)
30 if err != nil {
31 return nil, fmt.Errorf("reading config: %w", err)
32 }
33
34 c := Config{}
35 if err := yaml.Unmarshal(b, &c); err != nil {
36 return nil, fmt.Errorf("parsing config: %w", err)
37 }
38
39 return &c, nil
40}