Documentation ¶
Index ¶
- Constants
- Variables
- func BytesToString(b []byte) string
- func CamelString(s string) string
- func FuncName(fn interface{}) string
- func FuncNameFull(fn interface{}) string
- func HasWriteHeader(w http.ResponseWriter) bool
- func JSONDump(val interface{}, args ...interface{}) string
- func JSONExchange(dst interface{}, src interface{}) error
- func JSONMarshalToBase64(val interface{}) ([]byte, error)
- func JSONUnmarshalFromBase64(data []byte, val interface{}) error
- func JsMarshal(val interface{}) (bts []byte)
- func JsMarshalIndent(val interface{}) (bts []byte)
- func NewValue(bean interface{}) (val interface{})
- func ObjectTagInstances(obj interface{}, tagName string) []interface{}
- func ParsePositionalArguments(rawArgs json.RawMessage, types []reflect.Type) ([]reflect.Value, error)
- func PopulateConstructor(value interface{}, args ...interface{})
- func ReflectValue(bean interface{}, fn func(v reflect.Value))
- func ReflectZeroFields(v interface{}, fields []string)
- func SetWriteHeader(w http.ResponseWriter)
- func SlicePointerValue(bean interface{}) reflect.Value
- func SliceStringContainsPrefix(slice []string, val string) bool
- func SnakeString(s string) string
- func StringToBytes(s string) []byte
- func ValueIndirect(val reflect.Value) reflect.Value
- type AfterHandler
- type BeforeHandler
- type Context
- func (c *Context) App() RPCServer
- func (c *Context) BeginRequest(w http.ResponseWriter, r *http.Request) *Context
- func (c *Context) BeginWithContext(ctx context.Context, w http.ResponseWriter, r *http.Request) *Context
- func (c *Context) Do(handlers ...Handler) error
- func (c *Context) IsStopped() bool
- func (c *Context) Method() string
- func (c *Context) Msg() *RPCMessage
- func (c *Context) Next() (err error)
- func (c *Context) Release()
- func (c *Context) Request() *http.Request
- func (c *Context) SetContext(ctx context.Context) *Context
- func (c *Context) SetMsg(msg *RPCMessage)
- func (c *Context) Stop()
- func (c *Context) Writer() http.ResponseWriter
- type ContextPool
- type Error
- type ErrorCode
- type ForbiddenError
- type Handler
- type HandlerCrypto
- type Handlers
- type IRPCError
- type ItfAfterCall
- type ItfBeforeCall
- type ItfConstructor
- type ItfExcludeMethod
- type ItfJ2rpcError
- type ItfNamespaceName
- type ItfStartup
- type Level
- type LevelLogger
- type Option
- type RPCMessage
- type RPCServer
- type TokenError
Constants ¶
const ( StartTimeKey = "__j2rpc_startTimeKey" EndTimeKey = "__j2rpc_endTimeKey" TimeUsedKey = "__j2rpc_timeUsedKey" )
Variables ¶
var SnakeOption = &Option{SnakeNamespace: true}
SnakeOption ...
Functions ¶
func BytesToString ¶
BytesToString convert []byte type to string type.
func CamelString ¶
CamelString converts the accepted string to a camel string (xx_yy to XxYy)
func FuncNameFull ¶
func FuncNameFull(fn interface{}) string
func HasWriteHeader ¶
func HasWriteHeader(w http.ResponseWriter) bool
func JSONExchange ¶
func JSONExchange(dst interface{}, src interface{}) error
JSONExchange ...使用json copy对象
func JSONMarshalToBase64 ¶
JSONMarshalToBase64 ...
func JSONUnmarshalFromBase64 ¶
JSONUnmarshalFromBase64 ...
func ObjectTagInstances ¶
func ObjectTagInstances(obj interface{}, tagName string) []interface{}
ObjectTagInstances ... *
- @Description:根据标签获取字段实例集合
- @param obj
- @param tagName
- @return []interface{}
func ParsePositionalArguments ¶
func ParsePositionalArguments(rawArgs json.RawMessage, types []reflect.Type) ([]reflect.Value, error)
ParsePositionalArguments tries to parse the given args to an array of values with the given types. It returns the parsed values or an error when the args could not be parsed. Missing optional arguments are returned as reflect.Zero|reflect.New values.
func PopulateConstructor ¶
func PopulateConstructor(value interface{}, args ...interface{})
PopulateConstructor ...
func ReflectValue ¶
ReflectValue ...回调函数
func ReflectZeroFields ¶
func ReflectZeroFields(v interface{}, fields []string)
ReflectZeroFields 将多个字段设置为零值
func SlicePointerValue ¶
SlicePointerValue ...构建类型切片
func SliceStringContainsPrefix ¶ added in v1.0.0
func SnakeString ¶
SnakeString converts the accepted string to a snake string (XxYy to xx_yy)
func StringToBytes ¶
StringToBytes convert string type to []byte type. NOTE: panic if modify the member value of the []byte.
Types ¶
type AfterHandler ¶
type BeforeHandler ¶
type Context ¶
type Context struct { context.Context Body []byte Store sync.Map // contains filtered or unexported fields }
func (*Context) BeginRequest ¶
BeginRequest ......
func (*Context) BeginWithContext ¶
func (c *Context) BeginWithContext(ctx context.Context, w http.ResponseWriter, r *http.Request) *Context
BeginWithContext ... start a new context with the given context
func (*Context) Msg ¶
func (c *Context) Msg() *RPCMessage
func (*Context) SetContext ¶
SetContext ......
func (*Context) SetMsg ¶
func (c *Context) SetMsg(msg *RPCMessage)
type ContextPool ¶
type Error ¶
type Error struct { Code ErrorCode `json:"code"` Message string `json:"message,omitempty"` Data interface{} `json:"data,omitempty"` }
Error ... Error codes
type ForbiddenError ¶
type ForbiddenError string
ForbiddenError ...
func (ForbiddenError) Error ¶
func (e ForbiddenError) Error() string
type HandlerCrypto ¶ added in v1.0.0
func ParseHandlerCrypto ¶ added in v1.0.0
func ParseHandlerCrypto(str string) *HandlerCrypto
ParseHandlerCrypto ... str format: base64:xxx or xxx if str is empty, return nil if str is not start with base64:, return &HandlerCrypto{Key: str} if str is start with base64:, return &HandlerCrypto{Key: str[7:], UseBase64: true} if str[7:] is empty, return nil
type ItfAfterCall ¶
type ItfBeforeCall ¶
type ItfExcludeMethod ¶
type ItfExcludeMethod interface {
ExcludeMethod() []string
}
ItfExcludeMethod ...
type ItfJ2rpcError ¶ added in v1.0.0
type ItfNamespaceName ¶
type ItfNamespaceName interface {
J2rpcNamespaceName() string
}
ItfNamespaceName ...
type ItfStartup ¶
type ItfStartup interface {
Startup(rs RPCServer)
}
type Level ¶
type Level uint32
Level type
level
func ParseLevel ¶
ParseLevel takes a string level and returns the log level constant.
func (*Level) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
type LevelLogger ¶
type LevelLogger interface { SetOutput(io.Writer) Writer() io.Writer Print(...interface{}) Printf(string, ...interface{}) Println(...interface{}) Fatal(...interface{}) Fatalf(string, ...interface{}) Fatalln(...interface{}) Panic(...interface{}) Panicf(string, ...interface{}) Panicln(...interface{}) Debugf(string, ...interface{}) Infof(string, ...interface{}) Warnf(string, ...interface{}) Errorf(string, ...interface{}) }
LevelLogger ...
func NewLevelLogger ¶
func NewLevelLogger(prefix string, out ...io.Writer) LevelLogger
NewLevelLogger ...
type Option ¶
type Option struct { SnakeNamespace bool Service interface{} Logger LevelLogger //CryptoKey request/response crypto key, default is nil (no crypto) CryptoKey string }
Option ...
func (*Option) ParseRPCBody ¶ added in v1.0.0
type RPCMessage ¶
type RPCMessage struct { ID json.RawMessage `json:"id,omitempty"` Version string `json:"jsonrpc,omitempty"` Method string `json:"method,omitempty"` Params json.RawMessage `json:"params,omitempty"` Result json.RawMessage `json:"result,omitempty"` Error *Error `json:"error,omitempty"` }
RPCMessage A value of this type can a JSON-RPC request, notification, successful response or error response. Which one it is depends on the fields.
func RPCError ¶
func RPCError(err error) *RPCMessage
func RPCResult ¶
func RPCResult(result interface{}) *RPCMessage
type RPCServer ¶
type RPCServer interface { SetCallBefore(before BeforeHandler) SetCallAfter(after AfterHandler) GetContext() *Context Use(handlers ...Handler) Opt() *Option Logger() LevelLogger SetLogger(logger LevelLogger) ServeHTTP(w http.ResponseWriter, r *http.Request) RegisterForApp(app interface{}) Register(receiver interface{}, names ...string) Handler(ctx *Context) Stop() NamespaceService(method string) interface{} }
RPCServer ...
type TokenError ¶
type TokenError string
TokenError ...
func (TokenError) Error ¶
func (t TokenError) Error() string