Repository navigation
Expand file tree
/
Copy pathConfig.go
More file actions
62 lines (53 loc) · 1.44 KB
/
Copy pathConfig.go
File metadata and controls
62 lines (53 loc) · 1.44 KB
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
package config
import (
"encoding/json"
"fmt"
"os"
)
/*
* ConfigurationStruct holds some generic configuration information but is
* primarily there to hang the related methods off of.
*/
type ConfigurationStruct struct {
//Basic Site Configuration
Hosts string
StaticPath string
TemplateRoot string
//Basic Security Configuration
AdminToken string
MinimumNameLength int
MinPasswordLength int
EncKey string
AuthKey string
CookieName string
//Database Configuration
DatabaseName string
DatabaseUserName string
DatabasePassword string
DatabaseServerURL string
DatabaseOptions string
}
//LoadConfigs loads a configuration file and stuffs it into the interface named config.
func LoadConfigs(config interface{}, envVariable string) {
configPath := getConfigPath(envVariable)
file, err := os.Open(configPath)
if err != nil {
panic("Configuration file did not open!")
}
decoder := json.NewDecoder(file)
err = decoder.Decode(&config)
if err != nil {
fmt.Println("Configuration File Malformed")
panic(err)
}
}
//getConfigPath() Gets the config path from the environmental variable.
func getConfigPath(envVariable string) string {
//First we figure out where the configuration files should be.
configpath, isEnv := os.LookupEnv(envVariable)
if !isEnv {
fmt.Println("Could not find the env variable for the configs.")
panic("No env variable for configs.")
}
return configpath
}