arnaucube
arnaucube/blogoPublic Self-hosted repository
blogo/readConfig.go
readConfig.goRaw
 1package main
 2
 3import (
 4	"encoding/json"
 5	"io/ioutil"
 6)
 7
 8//Post is the struct for each post of the blog
 9type Post struct {
10	Thumb     string `json:"thumb"`
11	Md        string `json:"md"`
12	MetaImg   string `json:"metaimg"`
13	MetaDescr string `json:"metadescr"`
14}
15
16//Config gets the config.json file into struct
17type Config struct {
18	Title             string   `json:"title"`
19	MetaImg           string   `json:"metaimg"`
20	MetaDescr         string   `json:"metadescr"`
21	RelativePath      string   `json:"relativePath"`
22	PostsDir          string   `json:"postsDir"`
23	AbsoluteUrl       string   `json:"absoluteUrl"`
24	IndexTemplate     string   `json:"indexTemplate"`
25	PostThumbTemplate string   `json:"postThumbTemplate"`
26	Posts             []Post   `json:"posts"`
27	CopyRaw           []string `json:"copyRaw"`
28	OutputDir         string   `json:"outputDir"`
29}
30
31var config Config
32
33func readConfig(path string) {
34	file, err := ioutil.ReadFile(path)
35	check(err)
36	content := string(file)
37	json.Unmarshal([]byte(content), &config)
38	if config.PostsDir != "" {
39		config.PostsDir += "/"
40	}
41	if config.OutputDir == "" {
42		config.OutputDir = defaultOutputDir
43	}
44}