This repository has been archived by the owner on Apr 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
setting.go
118 lines (102 loc) · 2.69 KB
/
setting.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package main
import (
"gopkg.in/yaml.v2"
"flag"
"fmt"
"io/ioutil"
"os"
"path/filepath"
)
const yamlPath = ".syaronote.yaml"
var setting struct {
// server
syaroDir string
wikiRoot string
port int
urlPrefix string
fcgi bool
singleFile bool // TODO
gitMode bool
search bool
// console output
verbose bool
quiet bool
color bool
// bleve indexing
IndexingMode string `yaml:"indexing_mode"`
// authentication
Auth struct { // TODO
Mode string `yaml:"mode"`
Realm string `yaml:"realm"`
PermitReadNobody bool `yaml:"permit_read_nobody"`
User string `yaml:"user"`
Pass string `yaml:"pass"`
} `yaml:"auth"`
// markdown related
Markdown struct {
MathJax bool `yaml:"mathjax"`
Highlight bool `yaml:"highlight"`
Emoji bool `yaml:"emoji"`
} `yaml:"markdown"`
// post action
Actions struct {
// post actions
PostCreate []string `yaml:"post_create"`
PostUpdate []string `yaml:"post_update"`
PostRename []string `yaml:"post_rename"`
PostDelete []string `yaml:"post_remove"`
PostUpload []string `yaml:"post_upload"`
} `yaml:"actions"`
}
func init() {
// setting up flags
flag.IntVar(&setting.port, "port", 8080,
"Port number")
// flag.StringVar(&setting.urlPrefix, "url-prefix", "",
// "URL prefix (ex. if prefix is syarowiki, URL is localhost:PORT/syarowiki/)")
flag.BoolVar(&setting.fcgi, "fcgi", false,
"If true, syaro runs on fast cgi mode")
flag.BoolVar(&setting.singleFile, "single", false,
"Single file mode")
flag.BoolVar(&setting.gitMode, "gitmode", false,
"Enable git integration")
flag.BoolVar(&setting.verbose, "verbose", false,
"Verbose output")
flag.BoolVar(&setting.quiet, "quiet", false,
"Suppress output")
flag.BoolVar(&setting.color, "color", true,
"Colored output")
// usage
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "syaro %s\n\n", version)
fmt.Fprintf(os.Stderr, "Usage: %s [<flags>] [<wikiroot>]\n\nFlags:\n", os.Args[0])
flag.PrintDefaults()
fmt.Fprintf(os.Stderr, "\nArgs:\n wikiroot=\"./\": Root folder of wiki\n")
}
}
func parseFlags() {
flag.Parse()
if len(flag.Args()) > 0 {
setting.wikiRoot = filepath.Clean(flag.Arg(0)) // set wikiroot
} else {
setting.wikiRoot = "."
}
}
func loadYaml() {
// default values
setting.IndexingMode = "standard"
setting.Markdown.MathJax = true
setting.Markdown.Highlight = true
setting.Markdown.Emoji = true
b, err := ioutil.ReadFile(filepath.Join(setting.wikiRoot, yamlPath))
if err != nil {
log.Info(yamlPath + " not found")
return
}
err = yaml.Unmarshal(b, &setting)
if err != nil {
log.Error("Failed to load "+yamlPath+": %v", err)
return
}
log.Info("Load settings from " + yamlPath)
}