-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
45 lines (40 loc) · 972 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
43
44
45
package main
import (
_ "embed"
"flag"
"log"
"net/http"
"runtime"
"github.com/NYTimes/gziphandler"
"github.com/kiyor/devkit/controllers"
"github.com/kiyor/devkit/routers"
)
var (
intf string
port string
addr string
rootDir string
App string
host string
)
func init() {
flag.StringVar(&intf, "i", "0.0.0.0", "http service interface address")
flag.StringVar(&port, "l", ":8080", "http service listen port")
flag.StringVar(&host, "host", "", "Host with scheme")
flag.StringVar(&rootDir, "root", ".", "root dir")
}
func main() {
flag.Parse()
addr = intf + port
runtime.GOMAXPROCS(runtime.NumCPU())
log.SetFlags(log.LstdFlags | log.Lshortfile)
conf := routers.NewRouterConfig()
conf.RootDir = rootDir
conf.App = App
conf.Host = host
r := routers.NewRoutes(conf)
handler := controllers.NewLogHandler().Handler(r)
handler = gziphandler.GzipHandler(handler)
http.Handle("/", handler)
log.Fatal(http.ListenAndServe(addr, nil))
}