-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
52 lines (45 loc) · 1.25 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
package main
import (
"blog/middleware"
"blog/router"
"blog/util"
"embed"
"github.com/gin-gonic/gin"
)
func init() {
util.InitLog("log")
}
var (
//go:embed web/dist/*
buildFS embed.FS
//go:embed web/dist/index.html
indexPage []byte
ginConfig = util.CreateConfig("gin")
)
// 添加注释以描述 server 信息
// @title Swagger Example API
// @version 2.0
// @description This is a sample server celler 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 localhost:8080
// @BasePath /api/v1
// @securityDefinitions.basic BasicAuth
func main() {
//gin.SetMode(gin.ReleaseMode) // 设置为发布模式
//gin.Defaultwriter = io.Discard // 关闭gin的日志输出,所有的日志都会被丢弃
server := gin.Default()
err := server.SetTrustedProxies(ginConfig.GetStringSlice("trustedProxies"))
server.Use(middleware.CORSMiddleware())
server.Use(middleware.Metric())
// Router
router.SetRouter(server, buildFS, indexPage)
err = server.Run(ginConfig.GetString("port"))
if err != nil {
return
}
}