Skip to content

Commit

Permalink
perf: 使用变量代替字符串字面量
Browse files Browse the repository at this point in the history
  • Loading branch information
afzw committed Mar 24, 2024
1 parent 091a4ab commit 8c09fae
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions router/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,17 @@ import (
)

var (
apiUser api.UserApi
apiAuth api.AuthApi
apiUser api.UserApi
)

var (
authRoutesPrefix = "/auth"
serviceRoutesPrefix = "/api/v1"
)

var sessionName = "sid"

func InitRouter() {
//是否开启debug模式
if !config.DebugMode {
Expand All @@ -32,26 +39,25 @@ func InitRouter() {

if config.DebugMode {
engine.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
docs.SwaggerInfo.BasePath = authRoutesPrefix
}

docs.SwaggerInfo.BasePath = "/api/v1"

// session 设置
store := sessions.NewCookieStore([]byte(config.SessionSecret))
store.Options(sessions.Options{
Path: "/",
MaxAge: config.SessionExpire, // 设置超时时间为一个小时
})
engine.Use(sessions.Sessions("sid", store))
engine.Use(sessions.Sessions(sessionName, store))

// 日志设置
engine.Use(middleware.LogMiddleware())

// 登陆认证相关路由
authRouterGroup := engine.Group("/auth")
authRouterGroup := engine.Group(authRoutesPrefix)
authRouter(authRouterGroup)
// 业务路由
serviceRouterGroup := engine.Group("/api/v1")
serviceRouterGroup := engine.Group(serviceRoutesPrefix)
serviceRouterGroup.Use(middleware.SessionAuth())
userRouter(serviceRouterGroup)

Expand Down

0 comments on commit 8c09fae

Please sign in to comment.