all repos — legit @ e5d35c4deccd35a12b138d089dcd15a2c8ac18c1

web frontend for git, written in go

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	Server struct {
25		Name string `yaml:"name,omitempty"`
26		Host string `yaml:"host"`
27		Port int    `yaml:"port"`
28	} `yaml:"server"`
29}
30
31func Read(f string) (*Config, error) {
32	b, err := os.ReadFile(f)
33	if err != nil {
34		return nil, fmt.Errorf("reading config: %w", err)
35	}
36
37	c := Config{}
38	if err := yaml.Unmarshal(b, &c); err != nil {
39		return nil, fmt.Errorf("parsing config: %w", err)
40	}
41
42	return &c, nil
43}