1 Star 0 Fork 0

CaptialSTeam/ubdframe

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
api_server.go 2.95 KB
一键复制 编辑 原始数据 按行查看 历史
Souki 提交于 2025-07-28 10:27 +08:00 . !4modify api
package rssapp
import (
"gitee.com/captials-team/ubdframe/src/apps"
"gitee.com/captials-team/ubdframe/src/apps/rssapp/docs"
"gitee.com/captials-team/ubdframe/src/common"
"gitee.com/captials-team/ubdframe/src/common/utils"
"gitee.com/captials-team/ubdframe/src/domain/configstc"
"gitee.com/captials-team/ubdframe/src/domain/interfaces"
"gitee.com/captials-team/ubdframe/src/pkg/gin_http"
"gitee.com/captials-team/ubdframe/src/pkg/jwtauth"
v1log "gitee.com/captials-team/ubdframe/src/pkg/logs"
"github.com/gin-gonic/gin"
"go.uber.org/dig"
)
type ApiServer struct {
*apps.ApiServer
di *dig.Scope
conf *configstc.RssAppConfig
gin_http.AuthOption //认证相关选项配置
gin_http.SwaggerOption //swagger相关选项配置
gin_http.PProfOption //pprof选项配置
gin_http.OperateLogOption //操作日志
gin_http.AuthExtendInfoOption //认证扩展信息选项配置
gin_http.AccreditOption //授权选项
AdminAuth gin_http.AuthOption //管理站认证相关选项配置
}
func (s *ApiServer) Name() string {
return "rss_api"
}
func (s *ApiServer) InitRouter() {
s.Engine().GET("ping", gin_http.PingHandler)
s.InitRouterForGin(s.Engine())
}
func (s *ApiServer) router(g gin.IRouter) {
g.Use(
gin_http.PanicHandler,
gin_http.QPSLimiterHandler(10, 10),
)
//用于客户端
common.ErrPanic(s.di.Invoke(func(ctr interfaces.ItfRssController) {
g.POST("/rss/items", ctr.RssCacheItems)
}))
authGroup := g.Group("", s.OptAuthHandler(), s.OptAccreditHandler())
//管理站
common.ErrPanic(s.di.Invoke(func(ctr interfaces.ItfRssManageController) {
//rss原数据
authGroup.POST("/mag/rss/sources", ctr.RssSourceList)
authGroup.POST("/mag/rss/source/items", ctr.RssSourceItems)
}))
}
func (s *ApiServer) InitRouterForGin(engine *gin.Engine) {
var g = engine.Group("")
if len(s.conf.RoutePrefix) > 0 {
g = engine.Group(s.conf.RoutePrefix)
}
//注册swagger
s.SwaggerRouter(g)
//注册pprof
s.PProfRouter(engine)
s.router(g)
return
}
func (s *ApiServer) Start() error {
if !s.Module() {
s.InitRouter()
}
return s.ApiServer.Start()
}
func (s *ApiServer) Stop() error {
return s.ApiServer.Stop()
}
func NewApiServer(di *dig.Scope, conf *configstc.RssAppConfig, logger v1log.ILog) *ApiServer {
//swagger配置,取值后取指针是为了实现复用(多App)
swaggerDocs := *docs.SwaggerInforssservice
swaggerDocs.Host = conf.ApiServer.HostAddr() + utils.KeepHasPrefix(conf.RoutePrefix, "/")
s := &ApiServer{
di: di,
conf: conf,
SwaggerOption: gin_http.SwaggerOption{
Enable: conf.DocsEnable,
Name: swaggerDocs.InstanceName(),
Swagger: &swaggerDocs,
},
PProfOption: gin_http.PProfOption{
Enable: conf.PProfEnable,
},
ApiServer: apps.NewApiServer(gin.Default(), conf.ApiServer),
}
//开启跨域设置
s.ApiServer.WithCors()
if conf.AuthConfig.Enable {
s.AuthOption.AuthHandler = gin_http.AuthHandler(jwtauth.NewJwtTokenHandler(conf.AuthConfig.SecretKey))
}
return s
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/captials-team/ubdframe.git
git@gitee.com:captials-team/ubdframe.git
captials-team
ubdframe
ubdframe
v1.0.3

搜索帮助