mirror of
https://github.com/akyaiy/GoSally-mvp.git
synced 2026-01-03 17:52:24 +00:00
fix some bugs with params and add params type check
This commit is contained in:
@@ -24,6 +24,16 @@ func (h *HandlerV1) Handle(_ context.Context, sid string, r *http.Request, req *
|
|||||||
return rpc.NewError(rpc.ErrMethodNotFound, rpc.ErrMethodNotFoundS, nil, req.ID)
|
return rpc.NewError(rpc.ErrMethodNotFound, rpc.ErrMethodNotFoundS, nil, req.ID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
switch req.Params.(type) {
|
||||||
return h.handleLUA(sid, r, req, method)
|
case map[string]any, []any, nil:
|
||||||
|
return h.handleLUA(sid, r, req, method)
|
||||||
|
default:
|
||||||
|
// JSON-RPC 2.0 Specification:
|
||||||
|
// https://www.jsonrpc.org/specification#parameter_structures
|
||||||
|
//
|
||||||
|
// "params" MUST be either an *array* or an *object* if included.
|
||||||
|
// Any other type (e.g., a number, string, null, or boolean) is INVALID.
|
||||||
|
h.x.SLog.Info("invalid request received", slog.String("issue", rpc.ErrInvalidParamsS))
|
||||||
|
return rpc.NewError(rpc.ErrInvalidParams, rpc.ErrInvalidParamsS, nil, req.ID)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -100,6 +100,9 @@ func (h *HandlerV1) handleLUA(sid string, r *http.Request, req *rpc.RPCRequest,
|
|||||||
|
|
||||||
fetchedParamsTable := L.NewTable()
|
fetchedParamsTable := L.NewTable()
|
||||||
switch params := req.Params.(type) {
|
switch params := req.Params.(type) {
|
||||||
|
case nil:
|
||||||
|
print(1)
|
||||||
|
fetchedParamsTable.RawSetInt(1, lua.LNil)
|
||||||
case map[string]any:
|
case map[string]any:
|
||||||
for k, v := range params {
|
for k, v := range params {
|
||||||
L.SetField(fetchedParamsTable, k, ConvertGolangTypesToLua(L, v))
|
L.SetField(fetchedParamsTable, k, ConvertGolangTypesToLua(L, v))
|
||||||
@@ -108,6 +111,8 @@ func (h *HandlerV1) handleLUA(sid string, r *http.Request, req *rpc.RPCRequest,
|
|||||||
for i, v := range params {
|
for i, v := range params {
|
||||||
fetchedParamsTable.RawSetInt(i+1, ConvertGolangTypesToLua(L, v))
|
fetchedParamsTable.RawSetInt(i+1, ConvertGolangTypesToLua(L, v))
|
||||||
}
|
}
|
||||||
|
default:
|
||||||
|
fetchedParamsTable.RawSetInt(1, lua.LNil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -116,6 +121,9 @@ func (h *HandlerV1) handleLUA(sid string, r *http.Request, req *rpc.RPCRequest,
|
|||||||
def := L.Get(2)
|
def := L.Get(2)
|
||||||
|
|
||||||
get := func(tbl *lua.LTable, path string) lua.LValue {
|
get := func(tbl *lua.LTable, path string) lua.LValue {
|
||||||
|
if tbl.RawGetInt(1) == lua.LNil {
|
||||||
|
return lua.LNil
|
||||||
|
}
|
||||||
if path == "" {
|
if path == "" {
|
||||||
return tbl
|
return tbl
|
||||||
}
|
}
|
||||||
@@ -521,9 +529,8 @@ func (h *HandlerV1) handleLUA(sid string, r *http.Request, req *rpc.RPCRequest,
|
|||||||
return rpc.NewError(rpc.ErrInternalError, rpc.ErrInternalErrorS, nil, req.ID)
|
return rpc.NewError(rpc.ErrInternalError, rpc.ErrInternalErrorS, nil, req.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
resultVal := outTbl.RawGetString("result")
|
if resultVal := outTbl.RawGetString("result"); resultVal != lua.LNil {
|
||||||
if resultVal != lua.LNil {
|
return rpc.NewResponse(ConvertLuaTypesToGolang(resultVal), req.ID)
|
||||||
return rpc.NewResponse(ConvertLuaTypesToGolang(resultVal), req.ID)
|
|
||||||
}
|
}
|
||||||
return rpc.NewResponse(nil, req.ID)
|
return rpc.NewResponse(nil, req.ID)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user