-
Notifications
You must be signed in to change notification settings - Fork 43
/
main.go
47 lines (38 loc) · 1 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
package main
/*
* @Script: main.go
* @Author: pangxiaobo
* @Email: [email protected]
* @Create At: 2018-11-06 14:49:41
* @Last Modified By: pangxiaobo
* @Last Modified At: 2018-12-12 14:26:36
* @Description: This is description.
*/
import (
"fmt"
"net/http"
"runtime"
"github.com/gin-gonic/gin"
"github.com/xiaobopang/go_init/lib"
"github.com/xiaobopang/go_init/model"
"github.com/xiaobopang/go_init/router"
)
func main() {
serverConfig := lib.LoadServerConfig()
model.InitDB(serverConfig)
defer model.DB.Close()
gin.SetMode(serverConfig.RunMode)
//gin.DisableConsoleColor()
//set the number of CPU processor will be used
runtime.GOMAXPROCS(runtime.NumCPU())
router := router.SetupRouter()
s := &http.Server{
Addr: fmt.Sprintf(":%d", serverConfig.HTTPPort),
Handler: router,
ReadTimeout: serverConfig.ReadTimeout,
WriteTimeout: serverConfig.WriteTimeout,
MaxHeaderBytes: 1 << 20,
}
fmt.Println("Server init on port ", serverConfig.HTTPPort)
s.ListenAndServe()
}