j2rpc

package
v2.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2021 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SnakeOption = &Option{SnakeNamespace: true}

SnakeOption ...

Functions

func AbortWriteHeader

func AbortWriteHeader(w http.ResponseWriter, code int)

AbortWriteHeader ...

func BytesToString

func BytesToString(b []byte) string

BytesToString convert []byte type to string type.

func CamelString

func CamelString(s string) string

CamelString converts the accepted string to a camel string (xx_yy to XxYy)

func FuncName added in v2.2.1

func FuncName(fn interface{}) string

FuncName ...

func PopulateConstructor

func PopulateConstructor(value interface{})

PopulateConstructor ...

func SnakeString

func SnakeString(s string) string

SnakeString converts the accepted string to a snake string (XxYy to xx_yy)

func StringToBytes

func StringToBytes(s string) []byte

StringToBytes convert string type to []byte type. NOTE: panic if modify the member value of the []byte.

Types

type Error

type Error struct {
	Code    ErrorCode   `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data,omitempty"`
}

Error ... Error codes

func NewError

func NewError(code ErrorCode, Msg string, data ...interface{}) *Error

NewError ...

func (*Error) Error

func (e *Error) Error() string

type ErrorCode

type ErrorCode int

ErrorCode ... Error codes

const (
	ErrParse          ErrorCode = -32700
	ErrInvalidRequest ErrorCode = -32600
	ErrNoMethod       ErrorCode = -32601
	ErrBadParams      ErrorCode = -32602
	ErrInternal       ErrorCode = -32603
	ErrServer         ErrorCode = -32000
	ErrAuthorization  ErrorCode = 401
)

declared ...

type ItfConstructor

type ItfConstructor interface{ Constructor() }

ItfConstructor ...

type ItfExcludeMethod

type ItfExcludeMethod interface{ ExcludeMethod() []string }

ItfExcludeMethod ...

type Option

type Option struct {
	SnakeNamespace bool
	BeforeMid      []middleInfo
}

Option ...

func (*Option) AddBeforeMiddleware

func (o *Option) AddBeforeMiddleware(fn interface{}, ls ...[]string)

AddBeforeMiddleware ... *

  • @Description:
  • @receiver o
  • @param method
  • @param fn: //参数顺序: ctx,method,writer,request

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.

type RPCServer

type RPCServer interface {
	Opt() *Option
	Logger() g2util.LevelLogger
	SetLogger(logger g2util.LevelLogger)
	ServeHTTP(w http.ResponseWriter, r *http.Request)
	RegisterForApp(app interface{})
	Register(receiver interface{}, names ...string)
	Handler(ctx context.Context, w http.ResponseWriter, r *http.Request)
	Stop()
}

RPCServer ...

func New

func New(opts ...*Option) RPCServer

New ...

type TokenError added in v2.2.1

type TokenError string

TokenError ...

func (TokenError) Error added in v2.2.1

func (t TokenError) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL