feat: 优化web
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
authmw "giter.top/smart/internal/auth/middleware"
|
||||
"giter.top/smart/internal/iam/entity"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func atoiDef(s string, def int) int {
|
||||
if s == "" {
|
||||
return def
|
||||
}
|
||||
v, err := strconv.Atoi(s)
|
||||
if err != nil {
|
||||
return def
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// headerTenantID 当前租户:优先 OAuth2 Bearer 解析结果,其次 X-Tenant-ID,缺省平台租户。
|
||||
func headerTenantID(c *gin.Context) string {
|
||||
if v, ok := c.Get(authmw.CtxTenantID); ok {
|
||||
if s, ok2 := v.(string); ok2 && s != "" {
|
||||
return s
|
||||
}
|
||||
}
|
||||
s := c.GetHeader("X-Tenant-ID")
|
||||
if s == "" {
|
||||
return entity.PlatformTenantID
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
// headerUserID 当前用户:优先 OAuth2 opaque access_token 对应用户,其次 X-User-ID。
|
||||
func headerUserID(c *gin.Context) string {
|
||||
if v, ok := c.Get(authmw.CtxUserID); ok {
|
||||
if s, ok2 := v.(string); ok2 && s != "" {
|
||||
return s
|
||||
}
|
||||
}
|
||||
return c.GetHeader("X-User-ID")
|
||||
}
|
||||
|
||||
// headerGrantorUserID 请求头 X-Grantor-User-ID(授权人,用于防越权校验)
|
||||
func headerGrantorUserID(c *gin.Context) *string {
|
||||
s := c.GetHeader("X-Grantor-User-ID")
|
||||
if s == "" {
|
||||
return nil
|
||||
}
|
||||
return &s
|
||||
}
|
||||
Reference in New Issue
Block a user