Documentation ¶
Index ¶
- Constants
- Variables
- type CallContext
- type CallHandler
- type CallRequest
- type CallScheduler
- type ConcurrentScheduler
- type Endpoint
- func (ep *Endpoint) Dispatch(cr CallRequest) (CallHandler, error)
- func (ep *Endpoint) Register(name string, inst interface{}, ...) (*ServiceHandler, error)
- func (ep *Endpoint) Root(name string, inst interface{}, ...) (*ServiceHandler, error)
- func (ep *Endpoint) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (ep *Endpoint) Service(name string) (*ServiceHandler, bool)
- func (ep *Endpoint) Services() map[string]*ServiceHandler
- func (ep *Endpoint) Unregister(name string) error
- func (ep *Endpoint) Use(mw ...func(*CallContext, CallHandler) CallHandler)
- type HTTPCodec
- type MethodHandler
- type SequentialScheduler
- type ServiceHandler
Constants ¶
const DefaultConcurrencyLimit int64 = 3
DefaultConcurrencyLimit - default concurrency limit used by ConcurrentScheduler
Variables ¶
var ( // DefaultCallScheduler - default call execution scheduler DefaultCallScheduler = &SequentialScheduler{} )
Functions ¶
This section is empty.
Types ¶
type CallContext ¶
type CallContext struct { Request CallRequest // dispatch source provided by codec, used to construct codec response for this call Service string // target service name Method string // target method name Param reflect.Value // deserialized parameter Result reflect.Value // allocated result container }
CallContext - method call dispatch context. Captures information resolved by Endpoint into user middleware applied to handler. Exposes source call request protocol object and handler method information.
type CallHandler ¶
CallHandler - method call handling function
type CallRequest ¶
type CallRequest interface { Target() (string, string) // decode call request target service and method name Payload(interface{}) error // decode call request parameter payload into specific type pointer Result(interface{}, error) interface{} // construct result object specific for this request and protocol }
CallRequest - HTTPCodec single method call request object
type CallScheduler ¶
CallScheduler - used to execute multiple method calls decoded from request untill all methods finish or context gets cancelled
type ConcurrentScheduler ¶
type ConcurrentScheduler struct {
Limit uint // concurrency limit per request
}
ConcurrentScheduler - concurrently executing call scheduler.
type Endpoint ¶
type Endpoint struct {
// contains filtered or unexported fields
}
Endpoint - net/http request handler and RPC service registry. Decodes http requests using HTTPCodec and schedules procedure calls for execution using CallScheduler.
func NewEndpoint ¶
func NewEndpoint(codec HTTPCodec, sched CallScheduler, mw ...func(*CallContext, CallHandler) CallHandler) *Endpoint
NewEndpoint - creates new RPC endpoint, returns nil if codec is nil, registers endpoint-level middleware if provided.
func (*Endpoint) Dispatch ¶
func (ep *Endpoint) Dispatch(cr CallRequest) (CallHandler, error)
Dispatch - resolves service and method handlers and constructs CallHandler closure.
func (*Endpoint) Register ¶
func (ep *Endpoint) Register(name string, inst interface{}, mw ...func(*CallContext, CallHandler) CallHandler) (*ServiceHandler, error)
Register - registers RPC handler instance by service name. All exported instance methods matching following signature will be exposed for public access: func (*ExportedType) ExportedMethod(context.Context, *InType, *OutType) error Registering service with empty name returns result of Endpoint.Root method.
func (*Endpoint) Root ¶
func (ep *Endpoint) Root(name string, inst interface{}, mw ...func(*CallContext, CallHandler) CallHandler) (*ServiceHandler, error)
Root - registers RPC handler instance as namespace root. This service is used for method lookup when dispatched service name is empty.
func (*Endpoint) ServeHTTP ¶
func (ep *Endpoint) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP - decode request body into multiple call requests and execute them sequentially or concurrently.
func (*Endpoint) Service ¶
func (ep *Endpoint) Service(name string) (*ServiceHandler, bool)
Service - looks up service handler by name.
func (*Endpoint) Services ¶
func (ep *Endpoint) Services() map[string]*ServiceHandler
Services - returns copy of service handlers map.
func (*Endpoint) Unregister ¶
Unregister - remove service from endpoint.
func (*Endpoint) Use ¶
func (ep *Endpoint) Use(mw ...func(*CallContext, CallHandler) CallHandler)
Use - replaces endpoint middleware list.
type HTTPCodec ¶
type HTTPCodec interface { EncodeError(http.ResponseWriter, error) // send http response representing single error message EncodeResults(http.ResponseWriter, ...interface{}) // send http response representing one or more call results DecodeRequest(*http.Request) ([]CallRequest, error) // read and close http request body and decode one or more method call requests to execute, return (nil, nil) if request is valid but no calls was decoded }
HTTPCodec - request adapter interface implementing protocol validation and data (de-)serialization
type MethodHandler ¶
type MethodHandler struct { Meth reflect.Method // method pointer ReqType reflect.Type // signature parameter type ResType reflect.Type // signature result type }
MethodHandler - stores reflected method function reference and specific signature request/response types.
type SequentialScheduler ¶
type SequentialScheduler struct { }
SequentialScheduler - sequential execution call scheduler.
type ServiceHandler ¶
type ServiceHandler struct { Name string // name used to reference service in registry namespace Methods map[string]*MethodHandler // descriptors for methods with RPC handler compatible signature Inst reflect.Value // pointer to service instance InstType reflect.Type // type of service instance // contains filtered or unexported fields }
ServiceHandler - stores service instance, type, service-level middleware and method handlers collection.