-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
42 lines (35 loc) · 848 Bytes
/
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
package main
import (
"flag"
"net"
"net/http"
"os"
"runtime"
"github.com/sirupsen/logrus"
"github.com/fumiama/paper-manager/backend"
"github.com/fumiama/paper-manager/frontend"
)
func line() int {
_, _, fileLine, ok := runtime.Caller(1)
if ok {
return fileLine
}
return -1
}
func main() {
addr := flag.String("l", "[::]:3000", "listen addr")
flag.Parse()
l, err := net.Listen("tcp", *addr)
if err != nil {
logrus.Errorln("[net.Listen]", err)
os.Exit(line())
}
http.HandleFunc("/api/", backend.APIHandler)
http.HandleFunc("/file/", backend.FileHandler)
http.HandleFunc("/paper/", backend.PaperHandler)
http.HandleFunc("/upload", backend.UploadHandler)
http.Handle("/", frontend.StaticHandler)
logrus.Infoln("[http.Serve] start at", l.Addr())
logrus.Errorln("[http.Serve]", http.Serve(l, nil))
os.Exit(line())
}