mirror of
https://github.com/akyaiy/GoSally-mvp.git
synced 2026-01-03 20:12:25 +00:00
add response and error constructors
This commit is contained in:
22
internal/server/rpc/responsers.go
Normal file
22
internal/server/rpc/responsers.go
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
package rpc
|
||||||
|
|
||||||
|
import "encoding/json"
|
||||||
|
|
||||||
|
func NewError(code int, message string, id *json.RawMessage) *RPCResponse {
|
||||||
|
return &RPCResponse{
|
||||||
|
JSONRPC: JSONRPCVersion,
|
||||||
|
ID: id,
|
||||||
|
Error: map[string]any{
|
||||||
|
"code": code,
|
||||||
|
"message": message,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewResponse(result any, id *json.RawMessage) *RPCResponse {
|
||||||
|
return &RPCResponse{
|
||||||
|
JSONRPC: JSONRPCVersion,
|
||||||
|
ID: id,
|
||||||
|
Result: result,
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user