all repos — legit @ hide

web frontend for git

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	} `yaml:"meta"`
27	Server struct {
28		Name string `yaml:"name,omitempty"`
29		Host string `yaml:"host"`
30		Port int    `yaml:"port"`
31	} `yaml:"server"`
32}
33
34func Read(f string) (*Config, error) {
35	b, err := os.ReadFile(f)
36	if err != nil {
37		return nil, fmt.Errorf("reading config: %w", err)
38	}
39
40	c := Config{}
41	if err := yaml.Unmarshal(b, &c); err != nil {
42		return nil, fmt.Errorf("parsing config: %w", err)
43	}
44
45	if c.Repo.ScanPath, err = filepath.Abs(c.Repo.ScanPath); err != nil {
46		return nil, err
47	}
48	if c.Dirs.Templates, err = filepath.Abs(c.Dirs.Templates); err != nil {
49		return nil, err
50	}
51	if c.Dirs.Static, err = filepath.Abs(c.Dirs.Static); err != nil {
52		return nil, err
53	}
54
55	return &c, nil
56}