Documentation
¶
Index ¶
- Constants
- Variables
- func IndirectValue(val reflect.Value) reflect.Value
- func JSONDecode(data []byte, v interface{}) error
- func JSONEncode(v interface{}) ([]byte, error)
- func ZeroValue(typ reflect.Type) reflect.Value
- type CallerBody
- type Context
- type Decoder
- type Delim
- type Encoder
- type Error
- type ErrorCode
- type Group
- type Handler
- type ImplRPCMethodProvider
- type ImplRPCTypeName
- type ItfJ2rpcError
- type Option
- type RPCMessage
- type RawMessage
- type Server
- type ServerOption
Constants ¶
View Source
const ( BodyContextKey = "___j2rpc.body" TimeBeginContextKey = "___j2rpc.timeBegin" )
View Source
const Separator = "."
Variables ¶
View Source
var MethodNameProvider = func(name string) string { return strings.ToLower(name[:1]) + name[1:] }
Functions ¶
func JSONDecode ¶
func JSONEncode ¶
Types ¶
type CallerBody ¶
type Context ¶
type Context interface {
context.Context
Abort()
AddHandler(handlers ...Handler)
GetContext() context.Context
GetValue(key string) (interface{}, bool)
IsAbort() bool
Msg() *RPCMessage
Next()
Request() *http.Request
Server() Server
SetValue(key string, val interface{})
Writer() http.ResponseWriter
StopWriteStringStatus(status int, str string)
WriteResponse(args ...interface{})
Wrote() bool
}
func NewContext ¶
type Error ¶
type Error struct {
Code ErrorCode `json:"code"`
Message string `json:"message,omitempty"`
Data interface{} `json:"data,omitempty"`
}
Error ... Error codes
type ImplRPCMethodProvider ¶
type ImplRPCTypeName ¶
type ImplRPCTypeName interface {
RPCTypeName() string
}
type ItfJ2rpcError ¶
type Option ¶
type Option func(option *ServerOption)
func WithCallerAfterReadBody ¶
func WithCallerAfterReadBody(fn CallerBody) Option
func WithCallerBeforeWrite ¶
func WithCallerBeforeWrite(fn CallerBody) Option
type RPCMessage ¶
type RPCMessage struct {
ID RawMessage `json:"id,omitempty"`
Version string `json:"jsonrpc,omitempty"`
Method string `json:"method,omitempty"`
Params RawMessage `json:"params,omitempty"`
Result RawMessage `json:"result,omitempty"`
Error *Error `json:"error,omitempty"`
}
type RawMessage ¶
type RawMessage = json.RawMessage
type Server ¶
type Server interface {
Handler(c Context)
Option() *ServerOption
RegisterFunc(args ...interface{})
RegisterType(args ...interface{})
RegisterTypeBus(bus interface{})
ServeHTTP(writer http.ResponseWriter, request *http.Request)
Use(path string, handlers ...Handler) Group
}
type ServerOption ¶
type ServerOption struct {
CallerAfterReadBody CallerBody
CallerBeforeWrite CallerBody
}
Click to show internal directories.
Click to hide internal directories.