59 lines
1.3 KiB
Go
59 lines
1.3 KiB
Go
package router
|
|
|
|
import (
|
|
"github.com/pkg/errors"
|
|
"mini-chat/internal/alert"
|
|
"mini-chat/internal/api/admin"
|
|
"mini-chat/internal/cron"
|
|
"mini-chat/internal/dblogger"
|
|
"mini-chat/internal/pkg/core"
|
|
"mini-chat/internal/pkg/logger"
|
|
"mini-chat/internal/pkg/startup"
|
|
"mini-chat/internal/repository/mysql"
|
|
)
|
|
|
|
func NewHTTPMux(logger logger.CustomLogger, db mysql.Repo, cron cron.Server) (core.Mux, error) {
|
|
if logger == nil {
|
|
return nil, errors.New("logger required")
|
|
}
|
|
|
|
if db == nil {
|
|
return nil, errors.New("db required")
|
|
}
|
|
|
|
mux, err := core.New(logger,
|
|
core.WithEnableCors(),
|
|
core.WithEnableSwagger(),
|
|
core.WithEnablePProf(),
|
|
core.WithAlertNotify(alert.NotifyHandler()),
|
|
core.WithRequestLogger(dblogger.LoggerHandler(db)),
|
|
)
|
|
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
// 实例化拦截器
|
|
// interceptorHandler := interceptor.New(logger, db)
|
|
|
|
adminHandler := admin.New(logger, db)
|
|
|
|
// 管理端非认证接口路由组
|
|
adminNonAuthApiRouter := mux.Group("/admin")
|
|
{
|
|
adminNonAuthApiRouter.GET("/license/status", func(ctx core.Context) {
|
|
ctx.Payload(startup.Info())
|
|
})
|
|
|
|
adminNonAuthApiRouter.POST("/login", adminHandler.Login()) // 登录
|
|
}
|
|
|
|
// 管理端认证接口路由组
|
|
//adminAuthApiRouter := mux.Group("/admin", core.WrapAuthHandler(interceptorHandler.AdminTokenAuthVerify))
|
|
//{
|
|
//
|
|
//}
|
|
|
|
return mux, nil
|
|
}
|