this repo has no description
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 DBPath string `yaml:"dbpath"`
33
34 InternalHost string `yaml:"internalHost,omitempty"`
35 InternalPort int `yaml:"internalPort,omitempty"`
36 } `yaml:"server"`
37}
38
39func Read(f string) (*Config, error) {
40 b, err := os.ReadFile(f)
41 if err != nil {
42 return nil, fmt.Errorf("reading config: %w", err)
43 }
44
45 c := Config{}
46 if err := yaml.Unmarshal(b, &c); err != nil {
47 return nil, fmt.Errorf("parsing config: %w", err)
48 }
49
50 if c.Repo.ScanPath, err = filepath.Abs(c.Repo.ScanPath); err != nil {
51 return nil, err
52 }
53 if c.Dirs.Templates, err = filepath.Abs(c.Dirs.Templates); err != nil {
54 return nil, err
55 }
56 if c.Dirs.Static, err = filepath.Abs(c.Dirs.Static); err != nil {
57 return nil, err
58 }
59
60 return &c, nil
61}