all repos — elgit @ 878a52408ce37668d57284a344102e810b44b63e

fork of legit: web frontend for git, written in go

config/config.go (view raw)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package config

import (
	"fmt"
	"os"

	"gopkg.in/yaml.v3"
)

type Repo struct {
	Root       string   `yaml:"root"`
	Readme     []string `yaml:"readme"`
	MainBranch []string `yaml:"mainBranch"`
	Unlisted   []string `yaml:"unlisted,omitempty"`
}

type Meta struct {
	Title       string `yaml:"title"`
	Description string `yaml:"description"`
}

type Server struct {
	Name        string `yaml:"name,omitempty"`
	Host        string `yaml:"host"`
	Port        int64  `yaml:"port"`
	Compress    bool   `yaml:"compress"`
	Development bool   `yaml:"development"`
}

type Config struct {
	Repo   Repo   `yaml:"repo"`
	Meta   Meta   `yaml:"meta"`
	Server Server `yaml:"server"`
}

func Read(f string) (*Config, error) {
	b, err := os.ReadFile(f)
	if err != nil {
		return nil, fmt.Errorf("reading config: %w", err)
	}

	c := Config{}
	if err := yaml.Unmarshal(b, &c); err != nil {
		return nil, fmt.Errorf("parsing config: %w", err)
	}

	return &c, nil
}