-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
68 lines (57 loc) · 1.8 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
67
68
package main
import (
"crypto/tls"
"flag"
"fmt"
"gokit/config"
log "gokit/lib"
"gokit/routes"
"net/http"
"time"
"github.com/gin-gonic/gin"
)
func main() {
c := config.Config{}
Default := config.DefaultConfig()
flag.StringVar(&c.DbConn, "database", Default.DbConn, "Database DSN URL connection example: user:password@tcp(localhost:3303)/database")
flag.StringVar(&c.CacheConn, "cache", Default.CacheConn, "Redis DSN URL connection example: redis://username:password@host:port/0")
flag.StringVar(&c.GinMode, "gin-mode", Default.GinMode, "Gin Gonic Mode: dev|release")
flag.StringVar(&c.JwtToken, "jwt-token", Default.JwtToken, "JWT token")
flag.Int64Var(&c.JwtTimeout, "jwt-timeout", Default.JwtTimeout, "JWT token timeout in Time.Duration values default 1 Hour")
flag.IntVar(&c.Port, "port", Default.Port, "HTTP port default 80")
flag.Parse()
c.Init()
if c.GinMode == Default.GinMode {
log.BuildLogger("debug")
gin.SetMode(gin.DebugMode)
} else {
log.BuildLogger("info")
gin.SetMode(gin.ReleaseMode)
}
TlsConfig := &tls.Config{
// Causes servers to use Go's default ciphersuite preferences,
// which are tuned to avoid attacks. Does nothing on clients.
PreferServerCipherSuites: true,
// Only use curves which have assembly implementations
CurvePreferences: []tls.CurveID{
tls.CurveP256,
tls.X25519, // Go 1.8 only
},
}
s := &http.Server{
Addr: fmt.Sprintf(":%d", c.Port),
ReadHeaderTimeout: 5 * time.Second,
ReadTimeout: 5 * time.Second,
WriteTimeout: 30 * time.Second,
IdleTimeout: 10 * time.Second,
TLSConfig: TlsConfig,
Handler: routes.GetRouters(),
// MaxHeaderBytes: 1 << 20,
}
//Disable KeepAlive
s.SetKeepAlivesEnabled(false)
err := s.ListenAndServe()
if err != nil {
log.Log().Error(err.Error())
}
}