feat: 优化web

This commit is contained in:
2026-04-23 18:58:13 +08:00
commit 544a2f3428
160 changed files with 27327 additions and 0 deletions
+38
View File
@@ -0,0 +1,38 @@
package auth
import (
"giter.top/smart/internal/auth/handler"
"giter.top/smart/internal/auth/oauth2"
"github.com/gin-gonic/gin"
)
// AuthRoutes 认证相关 HTTPOAuth2、登录)。
type AuthRoutes struct {
bearer gin.HandlerFunc
loginRL gin.HandlerFunc
tokenRL gin.HandlerFunc
oauthH *oauth2.Handler
loginH *handler.LoginHandler
}
// NewAuthRoutes 构造(loginRL/tokenRL 使用 Wire 专用类型,见 wire_provider.go)。
func NewAuthRoutes(bearer gin.HandlerFunc, loginRL LoginRateLimitWire, tokenRL TokenRateLimitWire, oauthH *oauth2.Handler, loginH *handler.LoginHandler) *AuthRoutes {
return &AuthRoutes{
bearer: bearer,
loginRL: gin.HandlerFunc(loginRL),
tokenRL: gin.HandlerFunc(tokenRL),
oauthH: oauthH,
loginH: loginH,
}
}
// Register 实现 server.HttpRoutesOAuth 在根路径,/api/v1 挂 Bearer 与登录。
func (r *AuthRoutes) Register(engine *gin.Engine, apiGroup *gin.RouterGroup) {
apiGroup.Use(r.bearer)
apiGroup.POST("/auth/login", r.loginRL, r.loginH.Login)
apiGroup.POST("/auth/logout", r.loginH.Logout)
engine.GET("/oauth/authorize", r.oauthH.Authorize)
engine.POST("/oauth/token", r.tokenRL, r.oauthH.Token)
engine.POST("/oauth/introspect", r.tokenRL, r.oauthH.Introspect)
}