all repos — legit @ master

web frontend for git, written in go

config/config.go (view raw)

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