package config import ( "fmt" "os" "path/filepath" "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 Dirs struct { Static string `yaml:"static"` } type Meta struct { Title string `yaml:"title"` Description string `yaml:"description"` SyntaxHighlight string `yaml:"syntaxHighlight"` } type Server struct { Name string `yaml:"name,omitempty"` Host string `yaml:"host"` Port int `yaml:"port"` } type Config struct { Repo Repo `yaml:"repo"` Dirs Dirs `yaml:"dirs"` 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) } if c.Dirs.Static, err = filepath.Abs(c.Dirs.Static); err != nil { return nil, err } return &c, nil }