代码拉取完成,页面将自动刷新
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
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。