all repos — legit @ 49b8b292897031c0d60777edfca11867569b2ee6

web frontend for git

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		Ignore     []string `yaml:"ignore,omitempty"`
16	} `yaml:"repo"`
17	Dirs struct {
18		Templates string `yaml:"templates"`
19		Static    string `yaml:"static"`
20	} `yaml:"dirs"`
21	Meta struct {
22		Title       string `yaml:"title"`
23		Description string `yaml:"description"`
24	} `yaml:"meta"`
25	Server struct {
26		Name string `yaml:"name,omitempty"`
27		Host string `yaml:"host"`
28		Port int    `yaml:"port"`
29	} `yaml:"server"`
30}
31
32func Read(f string) (*Config, error) {
33	b, err := os.ReadFile(f)
34	if err != nil {
35		return nil, fmt.Errorf("reading config: %w", err)
36	}
37
38	c := Config{}
39	if err := yaml.Unmarshal(b, &c); err != nil {
40		return nil, fmt.Errorf("parsing config: %w", err)
41	}
42
43	return &c, nil
44}