all repos — legit @ 85d1bf73559536405d4eb22a6249a1e8d9030be3

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