-
Notifications
You must be signed in to change notification settings - Fork 8
/
chca.go
55 lines (37 loc) · 942 Bytes
/
chca.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
package chca
import (
"net/http"
"strconv"
"github.com/sirupsen/logrus"
)
var (
log = logrus.WithFields(logrus.Fields{
`MOD`: `chca`,
})
confile = "config.yml"
)
var conf = Config()
func Initialize() {
createConf()
createDir()
log.Debug("初始化成功!")
}
func ListenHttpServer(port int) {
log.Info("打开内置web服务器...")
p := strconv.Itoa(port)
http.Handle("/assets/", http.StripPrefix("/assets/", http.FileServer(http.Dir(conf.Html+"/assets/"))))
http.Handle("/", http.StripPrefix("/", http.FileServer(http.Dir(conf.Html))))
f := newFileHandler(conf.UploadTheme, conf.Markdown)
f.Http()
log.Debugf("内置web服务器开启成功,监听端口 :%d...", port)
err := http.ListenAndServe(":"+p, nil)
if err != nil {
log.Errorf("ListenAndServe: %s", err)
}
}
func init() {
log.Logger.SetFormatter(&logrus.TextFormatter{
ForceColors: true,
})
log.Logger.SetLevel(logrus.DebugLevel)
}