feat: 接口层同步 CallWithUser 与 ResScope 重命名
HTTPService.Invoke 新增 caller req.User 参数,指定时内部转发请求认证成该身份,配合 req-v2 新增的 Router.CallWithUser。 HttpController.AuthDB()、Orm.Model.SetAuthDB()、OrmController.AuthDB() 的返回值/参数类型从 req.ResAuthDB 同步改成 req.ResScope,跟 req-v2 那边的重命名保持一致。
This commit is contained in:
@@ -5,13 +5,9 @@ import (
|
||||
"net/http"
|
||||
|
||||
"git.fsdpf.net/go/req"
|
||||
"github.com/samber/do/v2"
|
||||
)
|
||||
|
||||
var defaultWsClientGroup WsClientGroup = "__DEFAULT__"
|
||||
var wsClientID WsClientID = 0
|
||||
|
||||
type Http interface {
|
||||
type HTTPService interface {
|
||||
// Start 启动 HTTP 服务。
|
||||
Start() error
|
||||
|
||||
@@ -28,11 +24,14 @@ type Http interface {
|
||||
// - path: 请求路径,如 "/api/user/list"。
|
||||
// - body: 请求体,无请求体时传 nil。
|
||||
// - headers: 附加请求头键值对,无需额外请求头时传 nil。
|
||||
// - caller: 指定认证中间件应认证成的调用者身份,为 nil 时按 headers 里的
|
||||
// Authorization/token 正常解析(等同于外部请求)。只有进程内部
|
||||
// 发起调用时才可能传非 nil 值,不受外部请求影响。
|
||||
//
|
||||
// 返回:
|
||||
// - *http.Response: 包含状态码、响应头及响应体的结果。
|
||||
// - error: 构造请求失败时返回错误。
|
||||
Invoke(method, path string, body io.Reader, header http.Header) (*http.Response, error)
|
||||
Invoke(method, path string, body io.Reader, header http.Header, caller req.User) (*http.Response, error)
|
||||
}
|
||||
|
||||
type HttpController interface {
|
||||
@@ -63,41 +62,5 @@ type HttpController interface {
|
||||
Call(code string, params map[string]any, category ...req.RouteMatchOption) (req.HttpResponse, error)
|
||||
|
||||
// AuthDB 返回当前控制器的数据库权限模式。
|
||||
AuthDB() req.ResAuthDB
|
||||
}
|
||||
|
||||
type HttpHandleController struct {
|
||||
Controller
|
||||
request *http.Request
|
||||
}
|
||||
|
||||
func (this HttpHandleController) Request() *http.Request {
|
||||
return this.request
|
||||
}
|
||||
|
||||
func (this HttpHandleController) Route() req.Route {
|
||||
return this.Request().Context().Value(req.RouteCtx{Name: "Route"}).(req.Route)
|
||||
}
|
||||
|
||||
func (this HttpHandleController) User() req.User {
|
||||
return this.Request().Context().Value(req.RouteCtx{Name: "User"}).(req.User)
|
||||
}
|
||||
|
||||
func (this HttpHandleController) Call(code string, params map[string]any, opts ...req.RouteMatchOption) (req.HttpResponse, error) {
|
||||
return do.MustInvoke[req.Router](this.Container()).Call(this.Request(), code, params, opts...)
|
||||
}
|
||||
|
||||
func (HttpHandleController) Execute(params req.GlobalParams) any {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (HttpHandleController) AuthDB() req.ResAuthDB {
|
||||
return req.ResAuthOn
|
||||
}
|
||||
|
||||
func NewHttpController(container do.Injector, request *http.Request) HttpController {
|
||||
return &HttpHandleController{
|
||||
Controller: &BaseController{container},
|
||||
request: request,
|
||||
}
|
||||
AuthDB() req.ResScope
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ const (
|
||||
OrmRightJoin RelationType = "right"
|
||||
)
|
||||
|
||||
type ModelDecorator func(Model) Model
|
||||
type ModelDecorator = func(Model) Model
|
||||
|
||||
type Orm interface {
|
||||
SetGlobalParams(g req.UserAccessor) Orm
|
||||
@@ -83,7 +83,7 @@ type Model interface {
|
||||
SetQueryField(...req.QueryField)
|
||||
// SetRelationResult(code string, items []reflux.R)
|
||||
GetJoinsCode() []string
|
||||
SetAuthDB(req.ResAuthDB)
|
||||
SetAuthDB(req.ResScope)
|
||||
SetOrderBy(params ...OrderBy) Model
|
||||
SetGroupBy(params ...GroupBy) Model
|
||||
SetJoin(Join) Model
|
||||
@@ -103,7 +103,7 @@ type Model interface {
|
||||
}
|
||||
|
||||
type OrmController interface {
|
||||
AuthDB() req.ResAuthDB
|
||||
AuthDB() req.ResScope
|
||||
}
|
||||
|
||||
type OrderBy interface {
|
||||
@@ -119,6 +119,8 @@ type GroupBy interface {
|
||||
type QueryWithRecursive interface {
|
||||
ToQueryBuilder(*db.SelectDataset, Model) (*db.SelectDataset, any)
|
||||
ToTreeData([]reflux.R) reflux.R
|
||||
// RootCondition 返回锚点条件(pField = root),供外部如 Count() 在不展开递归查询的情况下复用。
|
||||
RootCondition() exp.Expression
|
||||
}
|
||||
|
||||
// @title 创建关联模型
|
||||
|
||||
Reference in New Issue
Block a user