This repository has been archived by the owner on Aug 27, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
78 lines (63 loc) · 1.6 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
package main
import (
"code.google.com/p/goauth2/oauth"
"encoding/json"
"io/ioutil"
"log"
)
type Config struct {
Verbose bool
ContentFolder string
TemplateFolder string
Suffix string
WWWHost string
WWWRoot string
// Redis related
RedisHost string
RedisPass string
RedisDB int64
// OAuth2
ClientID string // app client id
ClientSecret string // supah secret app, secret
RedirectURL string // After the user authenticates where should we catch the response code.
AdminLogin string // There can only be one.
}
// Load up a JSON config file.
func (c *Config) LoadConfig(path string) {
f, err := ioutil.ReadFile(path)
if err != nil {
log.Panicln(err)
}
if err := json.Unmarshal(f, &c); err != nil {
log.Panicln(err)
}
oauth_config = oauth.Config{
ClientId: config.ClientID,
ClientSecret: config.ClientSecret,
Scope: "",
AuthURL: "https://github.com/login/oauth/authorize",
TokenURL: "https://github.com/login/oauth/access_token",
RedirectURL: config.RedirectURL,
}
}
// Generate a default config in the current directory for the user to manipulate.
func (c *Config) GenerateConfig(path string) {
c = &Config{
ContentFolder: "content",
TemplateFolder: "templates",
Suffix: ".md",
WWWHost: ":9000",
WWWRoot: "example",
RedisHost: "localhost:6379",
RedisPass: "",
RedisDB: -1,
Verbose: false,
// OAuth2
ClientID: "",
ClientSecret: "",
RedirectURL: "/callback",
AdminLogin: "",
}
b, _ := json.MarshalIndent(c, "", "\t")
ioutil.WriteFile(*conf, b, 0644)
}