-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.go
90 lines (77 loc) · 2.12 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package main
import (
"encoding/json"
"io/ioutil"
"log"
"os"
"strconv"
"strings"
)
type SeoConfig struct {
InformationText string `json:"informationText"`
DefaultSocialMessage string `json:"defaultSocialMessage"`
Description struct {
Episode string `json:"episode"`
Default string `json:"default"`
} `json:"description"`
Title struct {
Episode string `json:"episode"`
Default string `json:"default"`
} `json:"title"`
}
type SiteConfig struct {
Hostname string `json:"hostname"`
Theme string `json:"theme"`
FbConfig fbAccess `json:"fbConfig"`
SeoConfig SeoConfig `json:"seo"`
}
type ServerConfig struct {
env string
Port int `json:"port"`
DataDir string `json:"dataDir"`
ThemeDir string `json:"themeDir"`
SessionKey string `json:"sessionKey"`
FbAppID string `json:"fbAppId"`
FbAppSecret string `json:"fbAppSecret"`
Sites []SiteConfig
}
var Config ServerConfig
var configLocation string
func initConfig(file string) {
configLocation = file
log.Print("reading config from " + file)
configFile, err := ioutil.ReadFile(file)
if err != nil {
if os.IsNotExist(err) {
log.Fatal("config file does not exist")
} else {
log.Fatal("Config file could not be read")
}
}
json.Unmarshal(configFile, &Config)
Config.env = os.Getenv("LNB_ENV")
if Config.env != "development" && Config.env != "production" {
Config.env = "development"
}
}
func writeConfig() {
log.Println("writing config")
configString, err := json.MarshalIndent(&Config, "", " ")
if err != nil {
log.Fatal(err)
}
ioutil.WriteFile(configLocation, configString, 0666)
configContents, err := ioutil.ReadFile(configLocation)
if err != nil {
log.Fatal(err)
}
json.Unmarshal(configContents, &Config)
}
func buildMeta(input string, track ITrack) string {
epString := strconv.FormatInt(int64(*track.Episode), 10)
output := strings.Replace(input, "$$ARTIST", track.Artist, -1)
output = strings.Replace(output, "$$TITLE", track.Title, -1)
output = strings.Replace(output, "$$RELEASE", track.Release, -1)
output = strings.Replace(output, "$$EPISODE", epString, -1)
return output
}