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 Date string `json:"date"`
15 OutsideArticle string `json:"outsideArticle"`
16}
17
18// Config gets the config.json file into struct
19type Config struct {
20 Title string `json:"title"`
21 MetaImg string `json:"metaimg"`
22 MetaDescr string `json:"metadescr"`
23 RelativePath string `json:"relativePath"`
24 PostsDir string `json:"postsDir"`
25 AbsoluteUrl string `json:"absoluteUrl"`
26 IndexTemplate string `json:"indexTemplate"`
27 PostThumbTemplate string `json:"postThumbTemplate"`
28 Posts []Post `json:"posts"`
29 CopyRaw []string `json:"copyRaw"`
30 OutputDir string `json:"outputDir"`
31}
32
33var config Config
34
35func readConfig(path string) {
36 file, err := ioutil.ReadFile(path)
37 check(err)
38 content := string(file)
39 json.Unmarshal([]byte(content), &config)
40 if config.PostsDir != "" {
41 config.PostsDir += "/"
42 }
43 if config.OutputDir == "" {
44 config.OutputDir = defaultOutputDir
45 }
46}