-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
55 lines (45 loc) · 1.03 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
package main
import (
"flag"
"fmt"
"log"
"net/http"
"runtime"
"time"
"github.com/gin-gonic/gin"
)
var (
gitCommit = "undefined"
buildDate = "undefined"
port = flag.Int("port", 4242, "HTTP port to listen")
password = flag.String("password", "", "Admin password for basic auth")
apiKey = flag.String("apiKey", "42", "API key for header auth")
apiDir = flag.String("apiDir", "./api", "API directory (sh scripts and html pages)")
)
func ConfigRuntime() {
nuCPU := runtime.NumCPU()
runtime.GOMAXPROCS(nuCPU)
fmt.Printf("[info] Running with %d CPUs\n", nuCPU)
}
func StartGin() {
start := time.Now()
gin.SetMode(gin.ReleaseMode)
router := Router()
sport := fmt.Sprintf(":%d", *port)
s := &http.Server{
Addr: sport,
Handler: router,
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
MaxHeaderBytes: 1 << 20,
}
log.Printf("[info] API started in %v on %s\n", time.Since(start), sport)
for {
s.ListenAndServe()
}
}
func main() {
flag.Parse()
ConfigRuntime()
StartGin()
}