legit/config/config.go

41 lines
729 B
Go
Raw Normal View History

2022-12-11 05:52:47 +00:00
package config
import (
"fmt"
"os"
"gopkg.in/yaml.v3"
)
type Config struct {
Git struct {
2022-12-12 15:23:58 +00:00
ScanPath string `yaml:"scanPath"`
Readme []string `yaml:"readme"`
2022-12-11 05:52:47 +00:00
} `yaml:"git"`
Template struct {
Dir string `yaml:"dir"`
} `yaml:"template"`
Meta struct {
Title string `yaml:"title"`
Description string `yaml:"description"`
} `yaml:"meta"`
2022-12-12 17:28:23 +00:00
Server struct {
Host string `yaml:"host"`
Port int `yaml:"port"`
} `yaml:"server"`
2022-12-11 05:52:47 +00:00
}
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
}