-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
63 lines (55 loc) · 1.64 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
package main
import (
"crypto/tls"
"fmt"
"net/http"
"github.com/gin-gonic/gin"
"github.com/jameshwc/Million-Singer/conf"
"github.com/jameshwc/Million-Singer/model/mysql"
"github.com/jameshwc/Million-Singer/pkg/gredis"
"github.com/jameshwc/Million-Singer/pkg/log"
"github.com/jameshwc/Million-Singer/routers"
_ "github.com/joho/godotenv/autoload"
swaggerFile "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger"
)
func init() {
conf.Setup()
log.Setup()
gredis.Setup()
mysql.Setup()
}
// @title Million Singer API
// @version 1.0
// @description To add a level into database
// @contact.name jameshwc
// @contact.url https://jameshsu.csie.org
// @contact.email [email protected]
// @license.name GPL v3.0
// @license.url https://www.gnu.org/licenses/gpl-3.0.html
// @host ms.csie.org
// @BasePath /api
// @schemes http
func main() {
gin.SetMode(conf.ServerConfig.RunMode)
routers := routers.InitRouters()
endPoint := fmt.Sprintf(":%d", conf.ServerConfig.HttpPort)
maxHeaderBytes := 1 << 20
c := &tls.Config{MinVersion: tls.VersionTLS12}
server := &http.Server{
Addr: endPoint,
Handler: routers,
MaxHeaderBytes: maxHeaderBytes,
TLSConfig: c,
}
log.Infof("start http server listening %s", endPoint)
if gin.Mode() == gin.DebugMode {
apiDocURL := ginSwagger.URL(fmt.Sprintf(":%d/swagger/doc.json", conf.ServerConfig.HttpPort))
routers.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFile.Handler, apiDocURL))
}
if len(conf.ServerConfig.CertFile) > 0 {
log.Error(server.ListenAndServeTLS(conf.ServerConfig.CertFile, conf.ServerConfig.KeyFile))
} else {
log.Error(server.ListenAndServe())
}
}