Documentation
¶
Index ¶
- Constants
- func GetClientAddressFromHeader(r *http.Request) net.IP
- func GetClientAddressFromRequest(r *http.Request) net.IP
- func GetRealHostAddress(r *http.Request) string
- func GetRemoteAddress(r *http.Request) string
- type ErrorObject
- func ConvertIDtoString(id *json.RawMessage) (string, *ErrorObject)
- func GetPositionalFloat64Params(data ParametersObject) ([]float64, *ErrorObject)
- func GetPositionalInt64Params(data ParametersObject) ([]int64, *ErrorObject)
- func GetPositionalIntParams(data ParametersObject) ([]int, *ErrorObject)
- func GetPositionalStringParams(data ParametersObject) ([]string, *ErrorObject)
- func GetPositionalUint64Params(data ParametersObject) ([]uint64, *ErrorObject)
- func GetPositionalUintParams(data ParametersObject) ([]uint, *ErrorObject)
- type HookError
- type ParametersObject
- func (p ParametersObject) GetBasicAuth() (username, password string, ok bool)
- func (p ParametersObject) GetContentLength() int64
- func (p ParametersObject) GetCookies() []*http.Cookie
- func (p ParametersObject) GetHeaders() http.Header
- func (p ParametersObject) GetHost() string
- func (p ParametersObject) GetID() string
- func (p ParametersObject) GetMethod() string
- func (p ParametersObject) GetMethodName() string
- func (p ParametersObject) GetProto() string
- func (p ParametersObject) GetProtoMajor() int
- func (p ParametersObject) GetProtoMinor() int
- func (p ParametersObject) GetRawID() *json.RawMessage
- func (p ParametersObject) GetRawJSONParams() json.RawMessage
- func (p ParametersObject) GetReferer() string
- func (p ParametersObject) GetRemoteAddress() string
- func (p ParametersObject) GetRequestURI() string
- func (p ParametersObject) GetTrailer() http.Header
- func (p ParametersObject) GetTransferEncoding() []string
- func (p ParametersObject) GetUserAgent() string
- type RequestObject
- type ResponseObject
- func (r *ResponseObject) Marshal() []byte
- func (responseObject *ResponseObject) ValidateHTTPProtocolVersion(r *http.Request) bool
- func (responseObject *ResponseObject) ValidateHTTPRequestHeaders(r *http.Request) bool
- func (responseObject *ResponseObject) ValidateHTTPRequestMethod(r *http.Request) bool
- func (responseObject *ResponseObject) ValidateJSONRPCVersionNumber(version string) bool
- type Service
- func (s *Service) AddAuthorizationFromNetwork(network, username, password string) error
- func (s *Service) Call(name string, data ParametersObject) (interface{}, *ErrorObject)
- func (s *Service) CheckAuthorization(r *http.Request) error
- func (s *Service) GetAddress() string
- func (s *Service) GetBehidReverseProxyFlag() bool
- func (s *Service) GetCertificateFilePath() string
- func (s *Service) GetCertificateKeyFilePath() string
- func (s *Service) GetHeaders() map[string]string
- func (s *Service) GetRoute() string
- func (s *Service) GetSocket() string
- func (s *Service) GetSocketPermissions() uint32
- func (s *Service) Register(name string, f func(ParametersObject) (interface{}, *ErrorObject))
- func (s *Service) RegisterProxy(f func(ParametersObject) (interface{}, *ErrorObject))
- func (s *Service) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (s *Service) SetAddress(address string)
- func (s *Service) SetBehidReverseProxyFlag(flag bool)
- func (s *Service) SetCertificateFilePath(path string)
- func (s *Service) SetCertificateKeyFilePath(path string)
- func (s *Service) SetHeaders(headers map[string]string)
- func (s *Service) SetRequestHookFunction(f func(r *http.Request, data []byte) error)
- func (s *Service) SetResponseHookFunction(f func(r *http.Request, data []byte) error)
- func (s *Service) SetRoute(route string)
- func (s *Service) SetSocket(socket string)
- func (s *Service) SetSocketPermissions(mode uint32)
- func (s *Service) Start() error
- func (s *Service) StartTCPTLS() error
- func (s *Service) WriteRespose(w http.ResponseWriter, respObj *ResponseObject)
Constants ¶
const ( ParseErrorCode int = -32700 InvalidRequestCode int = -32600 MethodNotFoundCode int = -32601 InvalidParamsCode int = -32602 InternalErrorCode int = -32603 NotImplementedCode int = -32000 InvalidIDCode int = -32001 InvalidMethodCode int = -32002 )
Error codes.
const ( ParseErrorMessage string = "Parse error" InvalidRequestMessage string = "Invalid Request" MethodNotFoundMessage string = "Method not found" InvalidParamsMessage string = "Invalid params" InternalErrorMessage string = "Internal error" NotImplementedMessage string = "Not implemented" InvalidIDMessage string = "Invalid ID" InvalidMethodMessage string = "Invalid method" )
Error message.
const JSONRPCVersion string = "2.0"
JSONRPCVersion specifies the version of the JSON-RPC protocol.
Variables ¶
This section is empty.
Functions ¶
func GetClientAddressFromHeader ¶ added in v1.0.4
GetClientAddressFromHeader attempts to acquire Real Client IP (X-Real-IP, X-Client-IP) from upstream reverse proxy.
func GetClientAddressFromRequest ¶ added in v1.0.4
GetClientAddressFromRequest attempts to acquire Real Client IP from HTTP request.
func GetRealHostAddress ¶
GetRealHostAddress attempts to acquire original HOST from upstream reverse proxy.
func GetRemoteAddress ¶ added in v1.0.6
GetRemoteAddress returns remote address (IP) of request source.
Types ¶
type ErrorObject ¶
type ErrorObject struct {
// Code indicates the error type that occurred
Code int `json:"code"`
// Message provides a short description of the error
Message string `json:"message"`
// Data can contain additional information about the error
Data interface{} `json:"data,omitempty"`
}
ErrorObject represents a response error object.
func ConvertIDtoString ¶
func ConvertIDtoString(id *json.RawMessage) (string, *ErrorObject)
ConvertIDtoString converts ID parameter to string, also validates ID data type.
func GetPositionalFloat64Params ¶
func GetPositionalFloat64Params(data ParametersObject) ([]float64, *ErrorObject)
GetPositionalFloat64Params parses positional param member of JSON-RPC 2.0 request that is know to contain float64 array.
func GetPositionalInt64Params ¶
func GetPositionalInt64Params(data ParametersObject) ([]int64, *ErrorObject)
GetPositionalInt64Params parses positional param member of JSON-RPC 2.0 request that is know to contain int64 array.
func GetPositionalIntParams ¶
func GetPositionalIntParams(data ParametersObject) ([]int, *ErrorObject)
GetPositionalIntParams parses positional param member of JSON-RPC 2.0 request that is know to contain int array.
func GetPositionalStringParams ¶
func GetPositionalStringParams(data ParametersObject) ([]string, *ErrorObject)
GetPositionalStringParams parses positional param member of JSON-RPC 2.0 request that is know to contain string array.
func GetPositionalUint64Params ¶
func GetPositionalUint64Params(data ParametersObject) ([]uint64, *ErrorObject)
GetPositionalUint64Params parses positional param member of JSON-RPC 2.0 request that is know to contain int64 array.
func GetPositionalUintParams ¶
func GetPositionalUintParams(data ParametersObject) ([]uint, *ErrorObject)
GetPositionalUintParams parses positional param member of JSON-RPC 2.0 request that is know to contain uint array.
type HookError ¶ added in v1.0.1
HookError custom error for Request/Response hook.
func NewHookError ¶ added in v1.0.3
NewHookError creates new hook function error.
type ParametersObject ¶
type ParametersObject struct {
// contains filtered or unexported fields
}
ParametersObject represents input data for JSON-RPC 2.0 method.
func (ParametersObject) GetBasicAuth ¶
func (p ParametersObject) GetBasicAuth() (username, password string, ok bool)
GetBasicAuth returns returns the username and password provided in the request's Authorization header.
func (ParametersObject) GetContentLength ¶
func (p ParametersObject) GetContentLength() int64
GetContentLength returns the HTTP request content length.
func (ParametersObject) GetCookies ¶
func (p ParametersObject) GetCookies() []*http.Cookie
GetCookies parses and returns the HTTP cookies sent with the request.
func (ParametersObject) GetHeaders ¶
func (p ParametersObject) GetHeaders() http.Header
GetHeaders returns headers of the HTTP request.
func (ParametersObject) GetHost ¶
func (p ParametersObject) GetHost() string
GetHost returns the HTTP server host.
func (ParametersObject) GetID ¶
func (p ParametersObject) GetID() string
GetID returns request ID as string data type.
func (ParametersObject) GetMethod ¶
func (p ParametersObject) GetMethod() string
GetMethod returns the HTTP request method.
func (ParametersObject) GetMethodName ¶
func (p ParametersObject) GetMethodName() string
GetMethodName returns invoked request Method name as string data type.
func (ParametersObject) GetProto ¶
func (p ParametersObject) GetProto() string
GetProto returns the HTTP protocol version.
func (ParametersObject) GetProtoMajor ¶
func (p ParametersObject) GetProtoMajor() int
GetProtoMajor returns the HTTP protocol version, major part.
func (ParametersObject) GetProtoMinor ¶
func (p ParametersObject) GetProtoMinor() int
GetProtoMinor returns the HTTP protocol version, minor part.
func (ParametersObject) GetRawID ¶
func (p ParametersObject) GetRawID() *json.RawMessage
GetRawID returns request ID as json.RawMessage data type.
func (ParametersObject) GetRawJSONParams ¶
func (p ParametersObject) GetRawJSONParams() json.RawMessage
GetRawJSONParams returns json.RawMessage of JSON-RPC 2.0 invoked method params data.
func (ParametersObject) GetReferer ¶
func (p ParametersObject) GetReferer() string
GetReferer parses and returns the HTTP refere header sent with the request.
func (ParametersObject) GetRemoteAddress ¶
func (p ParametersObject) GetRemoteAddress() string
GetRemoteAddress returns remote address of request source.
func (ParametersObject) GetRequestURI ¶
func (p ParametersObject) GetRequestURI() string
GetRequestURI returns the HTTP protocol request URI.
func (ParametersObject) GetTrailer ¶
func (p ParametersObject) GetTrailer() http.Header
GetTrailer returns trailer headers of the HTTP request.
func (ParametersObject) GetTransferEncoding ¶
func (p ParametersObject) GetTransferEncoding() []string
GetTransferEncoding parses and returns TransferEncoding headers from the HTTP request.
func (ParametersObject) GetUserAgent ¶
func (p ParametersObject) GetUserAgent() string
GetUserAgent returns User Agent of client who made request.
type RequestObject ¶
type RequestObject struct {
// Jsonrpc specifies the version of the JSON-RPC protocol, equals to "2.0"
Jsonrpc string `json:"jsonrpc"`
// Method contains the name of the method to be invoked
Method string `json:"method"`
// Params holds Raw JSON parameter data to be used during the invocation of the method
Params json.RawMessage `json:"params"`
// ID is a unique identifier established by the client
ID *json.RawMessage `json:"id,omitempty"`
}
RequestObject represents a request object.
type ResponseObject ¶
type ResponseObject struct {
// Jsonrpc specifies the version of the JSON-RPC protocol, equals to "2.0"
Jsonrpc string `json:"jsonrpc"`
// Error contains the error object if an error occurred while processing the request
Error *ErrorObject `json:"error,omitempty"`
// Result contains the result of the called method
Result interface{} `json:"result,omitempty"`
// ID contains the client established request id or null
ID *json.RawMessage `json:"id,omitempty"`
// contains filtered or unexported fields
}
ResponseObject represents a response object.
func DefaultResponseObject ¶
func DefaultResponseObject() *ResponseObject
DefaultResponseObject initializes default response object.
func (*ResponseObject) Marshal ¶
func (r *ResponseObject) Marshal() []byte
Marshal create a bytes encoded representation of a single response object.
func (*ResponseObject) ValidateHTTPProtocolVersion ¶
func (responseObject *ResponseObject) ValidateHTTPProtocolVersion(r *http.Request) bool
ValidateHTTPProtocolVersion validates HTTP protocol version.
func (*ResponseObject) ValidateHTTPRequestHeaders ¶
func (responseObject *ResponseObject) ValidateHTTPRequestHeaders(r *http.Request) bool
ValidateHTTPRequestHeaders validates HTTP request headers.
func (*ResponseObject) ValidateHTTPRequestMethod ¶
func (responseObject *ResponseObject) ValidateHTTPRequestMethod(r *http.Request) bool
ValidateHTTPRequestMethod validates HTTP request method.
func (*ResponseObject) ValidateJSONRPCVersionNumber ¶
func (responseObject *ResponseObject) ValidateJSONRPCVersionNumber(version string) bool
ValidateJSONRPCVersionNumber validates JSON-RPC 2.0 request version member.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service represents a JSON-RPC 2.0 capable HTTP server.
func CreateOverTCPWithTLS ¶ added in v1.0.4
CreateOverTCPWithTLS defines a new service instance over TCP with TLS (HTTPS).
func CreateProxy ¶
CreateProxy defines a new proxy service over Unix Socket.
func CreateProxyOverTCPWithTLS ¶ added in v1.0.4
CreateProxyOverTCPWithTLS defines a new proxy service over TCP with TLS (HTTPS).
func (*Service) AddAuthorizationFromNetwork ¶ added in v1.0.2
AddAuthorizationFromNetwork adds (enables) Basic Authorization from supplyed remote network. Then at least one mapping exists, Basic Authorization is enabled, default action is Deny Access.
func (*Service) Call ¶
func (s *Service) Call(name string, data ParametersObject) (interface{}, *ErrorObject)
Call invokes the named method with the provided parameters.
func (*Service) CheckAuthorization ¶ added in v1.0.2
CheckAuthorization checks Basic Authorization then enabled by service configuration.
func (*Service) GetAddress ¶ added in v1.0.4
GetAddress gets custom network address from service object.
func (*Service) GetBehidReverseProxyFlag ¶ added in v1.0.4
GetBehidReverseProxyFlag gets behid reverse proxy flag from service object.
func (*Service) GetCertificateFilePath ¶ added in v1.0.4
GetCertificateFilePath gets path of Certificate file in service object.
func (*Service) GetCertificateKeyFilePath ¶ added in v1.0.4
GetCertificateKeyFilePath gets path of Certificate Key file in service object.
func (*Service) GetHeaders ¶ added in v1.0.4
GetHeaders gets custom headers from service object.
func (*Service) GetSocketPermissions ¶ added in v1.0.4
GetSocketPermissions gets custom unix socket permissions in service object.
func (*Service) Register ¶
func (s *Service) Register(name string, f func(ParametersObject) (interface{}, *ErrorObject))
Register maps the provided method name to the given function for later method calls.
func (*Service) RegisterProxy ¶
func (s *Service) RegisterProxy(f func(ParametersObject) (interface{}, *ErrorObject))
RegisterProxy maps the 'rpc.proxy' method name to the given function for later method calls.
func (*Service) ServeHTTP ¶
func (s *Service) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements needed interface for HTTP library, handles incoming RPC client requests, generates responses.
func (*Service) SetAddress ¶ added in v1.0.4
SetAddress sets custom network address in service object.
func (*Service) SetBehidReverseProxyFlag ¶ added in v1.0.4
SetBehidReverseProxyFlag sets behid reverse proxy flag in service object.
func (*Service) SetCertificateFilePath ¶ added in v1.0.4
SetCertificateFilePath sets path to Certificate file in service object.
func (*Service) SetCertificateKeyFilePath ¶ added in v1.0.4
SetCertificateKeyFilePath sets path to Certificate Key file in service object.
func (*Service) SetHeaders ¶
SetHeaders sets custom headers in service object.
func (*Service) SetRequestHookFunction ¶
SetRequestHookFunction defines function that will be used as request hook.
func (*Service) SetResponseHookFunction ¶
SetResponseHookFunction defines function that will be used as request hook.
func (*Service) SetSocketPermissions ¶
SetSocketPermissions sets custom unix socket permissions in service object.
func (*Service) Start ¶
Start binds the RPCHandler to the server route and starts the HTTP server over Unix Socket.
func (*Service) StartTCPTLS ¶ added in v1.0.4
StartTCPTLS binds the RPCHandler to the server route and starts the HTTP server over TCP.
func (*Service) WriteRespose ¶
func (s *Service) WriteRespose(w http.ResponseWriter, respObj *ResponseObject)
WriteRespose writes JSON-RPC 2.0 response object to HTTP response writer.