/
config.go
45 lines (40 loc) · 1.04 KB
/
config.go
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
package main
import (
"io/ioutil"
"gopkg.in/yaml.v3"
"github.com/brothertoad/btu"
)
type gossConfig struct {
PageDir string `yaml:"pageDir"`
LayoutDir string `yaml:"layoutDir"`
DataDir string `yaml:"dataDir"`
PerPageDataDir string `yaml:"perPageDataDir"`
OutputDir string `yaml:"outputDir"`
Clean bool `yaml:"clean"`
Pre interface{} `yaml:"pre"`
Post interface{} `yaml:"post"`
ModTimeFormat string `yaml:"modTimeFormat"`
}
const DEFAULT_CONFIG_FILE = "goss.yaml"
func initConfig(config *gossConfig) {
config.PageDir = "pages"
config.LayoutDir = "layouts"
config.DataDir = "data"
config.OutputDir = "public"
config.Clean = true
config.Pre = ""
config.Post = ""
loadConfig(config, DEFAULT_CONFIG_FILE, false)
}
func loadConfig(config *gossConfig, path string, fileMustExist bool) {
if !btu.FileExists(path) {
if fileMustExist {
btu.Fatal("Config file %s does not exist.\n", path)
}
return
}
b, err := ioutil.ReadFile(path)
btu.CheckError(err)
err = yaml.Unmarshal(b, config)
btu.CheckError(err)
}