This repository has been archived by the owner on Mar 22, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
66 lines (59 loc) · 1.61 KB
/
main.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
package main
import (
"flag"
"os"
"github.com/sirupsen/logrus"
"github.com/valyala/fasthttp"
"toast.cafe/x/webdd/middleware"
"toast.cafe/x/webdd/util"
)
func main() {
// ---- Flags
wd, _ := os.Getwd()
flag.BoolVar(&util.S.Asciidoc, "asciidoc", true, "preparse asciidoc files")
flag.StringVar(&util.S.Dir, "directory", wd, "directory to serve")
flag.BoolVar(&util.S.Log, "log", true, "log all requests")
flag.StringVar(&util.S.LogLevel, "loglevel", "info", "log level to display")
flag.BoolVar(&util.S.Markdown, "markdown", true, "prepare markdown files")
flag.BoolVar(&util.S.Safe, "safe", false, "re-sanitize requests")
flag.Parse()
// Setup Logging
log := logrus.New()
loglevel, err := logrus.ParseLevel(util.S.LogLevel)
if err != nil {
loglevel = logrus.InfoLevel
log.Warning("could not parse log level, defaulting to info")
}
log.SetLevel(loglevel)
// ---- Report Flags
log.WithFields(logrus.Fields{
"asciidoc": util.S.Asciidoc,
"directory": util.S.Dir,
"log": util.S.Log,
"loglevel": util.S.LogLevel,
"markdown": util.S.Markdown,
"safe": util.S.Safe,
}).Trace("compiled settings")
// ---- Prepare Middlewares
var md []middleware.Middleware
if util.S.Safe {
md = append(md, middleware.Safe)
}
if util.S.Log {
md = append(md, middleware.HTTPLog)
}
if util.S.Asciidoc {
md = append(md, middleware.ASCIIDoc)
}
if util.S.Markdown {
md = append(md, middleware.MarkDown)
}
md = append(md, middleware.File)
handler := middleware.HandleMiddlewares(md)
// ---- Launch Server
s := &fasthttp.Server{
Handler: handler,
Logger: log,
}
s.ListenAndServe(":8080")
}