-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.go
53 lines (43 loc) · 1.26 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
package main
import (
"fmt"
"github.com/gin-gonic/gin"
"hertz/pkg/setting"
"hertz/routes"
"net/http"
swaggerFiles "github.com/swaggo/files"
"github.com/swaggo/gin-swagger"
_ "hertz/docs" // docs is generated by Swag CLI, you have to import it.
)
// @title Swagger Example API
// @version 1.0
// @description This is a sample server Petstore server.
// @termsOfService http://swagger.io/terms/
// @contact.name API Support
// @contact.url http://www.swagger.io/support
// @contact.email [email protected]
// @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
// @host petstore.swagger.io
// @BasePath /v2
func main() {
//设置框架启动模式
gin.SetMode(setting.RunMode)
//获取路由
route := gin.Default()
routes.CreateRoutes(route)
if (setting.AppDebug) {
url := ginSwagger.URL("http://localhost:9000/swagger/doc.json") // The url pointing to API definition
route.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler, url))
}
//配置服务
server := &http.Server{
Addr: fmt.Sprintf(":%d", setting.HTTPPort),
Handler: route,
ReadTimeout: setting.ReadTimeout,
WriteTimeout: setting.WriteTimeout,
MaxHeaderBytes: 1 << 20,
}
//服务启动
server.ListenAndServe()
}