summaryrefslogblamecommitdiffstats
path: root/config/config.go
blob: 68671297ceeb639d9a3456a3d8094bfb189f5665 (plain) (tree)
1
2
3
4
5
6
7
8
9
10









                          




                                                       



                                                   



                                                       

                                 
                                                           

                                   
                       
                                                   
                                         
                                         
                         














                                                                 
package config

import (
	"fmt"
	"os"

	"gopkg.in/yaml.v3"
)

type Config struct {
	Repo struct {
		ScanPath   string   `yaml:"scanPath"`
		Readme     []string `yaml:"readme"`
		MainBranch []string `yaml:"mainBranch"`
	} `yaml:"repo"`
	Dirs struct {
		Templates string `yaml:"templates"`
		Static    string `yaml:"static"`
	} `yaml:"dirs"`
	Meta struct {
		Title       string `yaml:"title"`
		Description string `yaml:"description"`
	} `yaml:"meta"`
	Misc struct {
		GoImport struct {
			PrettyURL string `yaml:"prettyURL"`
		} `yaml:"goImport"`
	} `yaml:"misc"`
	Server struct {
		FQDN string `yaml:"fqdn,omitempty"`
		Host string `yaml:"host"`
		Port int    `yaml:"port"`
	} `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
}