Documentation ¶
Index ¶
- Constants
- Variables
- func Any(_ ReadPeeker) bool
- func NewError(code StatusCode, format string, args ...interface{}) *errors.CodedError
- func RegisterBalancer(b BalancerBuilder)
- func RegisterCodec(name string, cb CodecBuilder)
- func RegisterNewer(t reflect.Type, n Newer)
- func StatusOf(err error) int32
- type Action
- type ActionSet
- type AsyncError
- type Balancer
- type BalancerBuilder
- type BalancerOptions
- type CFilter
- type CHandler
- type Call
- type Channel
- func (c *Channel) Flush() error
- func (c *Channel) ID() string
- func (c *Channel) Peek(n int) ([]byte, error)
- func (c *Channel) Read(p []byte) (n int, err error)
- func (c *Channel) ReadByte() (byte, error)
- func (c *Channel) ReadBytes(delim byte) ([]byte, error)
- func (c *Channel) ReadString(delim byte) (string, error)
- func (c *Channel) Reader() *bufio.Reader
- func (c *Channel) Write(p []byte) (n int, err error)
- func (c *Channel) WriteByte(b byte) error
- func (c *Channel) WriteString(s string) (int, error)
- func (c *Channel) Writer() *bufio.Writer
- type Client
- type ClientCodec
- type ClientOptions
- type CodecBuilder
- type Context
- type FailMode
- type LazyClient
- type Matcher
- type Newer
- type Node
- type NodeOptions
- type ReadPeeker
- type Request
- type RequestHead
- type Response
- type ResponseHead
- type Result
- type SFilter
- type SHandler
- type Server
- func (s *Server) Close(timeout time.Duration)
- func (s *Server) Match(m Matcher, codec string, opts ...data.Map)
- func (s *Server) RegisterFunc(service, method string, fn interface{}, filter ...SFilter) error
- func (s *Server) RegisterService(name string, svc interface{}, filter ...SFilter) error
- func (s *Server) Serve() error
- func (s *Server) Sessions() SessionMap
- func (s *Server) Use(filter ...SFilter)
- type ServerCodec
- type ServerOptions
- type Session
- type SessionMap
- type Stats
- type StatusCode
- type Stream
Constants ¶
View Source
const PkgName = "auxo.net.rpc"
Variables ¶
View Source
var ( NewError(StatusNodeUnavailable, "rpc: no node is available") // ErrNodeShutdown indicates Node is shut down. ErrNodeShutdown = NewError(StatusNodeShutdown, "rpc: node is shut down") // ErrNilResult indicates the return value is nil. ErrNilResult = NewError(StatusNilResult, "rpc: result is nil") // ErrServerClosed indicates Server is closed. ErrServerClosed = NewError(StatusServerClosed, "rpc: server closed") )ErrNodeUnavailable =
View Source
var (
ClientPool = clientManager{/* contains filtered or unexported fields */}
)
Functions ¶
func NewError ¶
func NewError(code StatusCode, format string, args ...interface{}) *errors.CodedError
func RegisterBalancer ¶
func RegisterBalancer(b BalancerBuilder)
func RegisterCodec ¶
func RegisterCodec(name string, cb CodecBuilder)
func RegisterNewer ¶
Types ¶
type Action ¶
type Action interface { // Name is the name of action, normally is '[Service].[Method]' Name() string // In returns input arguments of the action In() []reflect.Type // Out returns output arguments of the action Out() []reflect.Type // Context returns true if the first in-arg is `context.Context` Context() bool // Error returns true if the last out-arg is `error` Error() bool // Handler returns real executor of the action Handler() SHandler // contains filtered or unexported methods }
Action is the interface that wraps the methods of service executor.
type AsyncError ¶
type AsyncError interface {
Wait() error
}
type BalancerBuilder ¶
type BalancerBuilder interface { // Name returns the name of balancers built by this builder. // It will be used to pick balancers (for example in service config). Name() string // Build creates a new balancer with the options. Build(opts data.Map) Balancer }
BalancerBuilder creates a balancer.
func GetBalancer ¶
func GetBalancer(name string) BalancerBuilder
type BalancerOptions ¶
type BalancerOptions struct { }
type Call ¶
type Call struct {
// contains filtered or unexported fields
}
func (*Call) SetContext ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func AutoClient ¶
AutoClient loads options from config file and create a Client. The created client is cached, so next call AutoClient with the same name will return the same Client instance.
func NewClient ¶
func NewClient(opts ClientOptions) (*Client, error)
NewClient creates Client with options.
type ClientCodec ¶
type ClientOptions ¶
type ClientOptions struct { Name string `json:"name" yaml:"name"` Desc string `json:"desc" yaml:"desc"` Version string `json:"version" yaml:"version"` Group string `json:"group" yaml:"group"` Fail FailMode `json:"fail" yaml:"fail"` Address []transport.Address `json:"address" yaml:"address"` Codec struct { Name string `json:"name" yaml:"name"` Options data.Map `json:"options" yaml:"options"` } `json:"codec" yaml:"codec"` Balancer struct { Name string `json:"name" yaml:"name"` Options data.Map `json:"options" yaml:"options"` } `json:"balancer" yaml:"balancer"` Resolver struct { Name string `json:"name" yaml:"name"` Options data.Map `json:"options" yaml:"options"` } `json:"resolver" yaml:"resolver"` Channels int `json:"channels" yaml:"channels"` CallTimeout time.Duration `json:"call_timeout" yaml:"call_timeout"` DialTimeout time.Duration `json:"dial_timeout" yaml:"dial_timeout"` ReadTimeout time.Duration `json:"read_timeout" yaml:"read_timeout"` WriteTimeout time.Duration `json:"write_timeout" yaml:"write_timeout"` }
func (*ClientOptions) AddAddress ¶
func (opts *ClientOptions) AddAddress(uri string, options data.Map)
type CodecBuilder ¶
type CodecBuilder interface { NewClient(s Stream, opts data.Map) ClientCodec NewServer(s Stream, opts data.Map) ServerCodec }
type Context ¶
type Context interface { Request() *Request Action() Action Context() ct.Context SetContext(ctx ct.Context) // User returns info of current visitor. User() security.User // SetUser set user info of current visitor. Generally used by authentication filter. SetUser(user security.User) }
func FromContext ¶
type LazyClient ¶
type LazyClient struct { Name string // contains filtered or unexported fields }
func (*LazyClient) Get ¶
func (l *LazyClient) Get() (c *Client)
func (*LazyClient) Try ¶
func (l *LazyClient) Try() (c *Client, err error)
type Matcher ¶
type Matcher func(p ReadPeeker) bool
Matcher matches a connection based on it's content.
type NodeOptions ¶
type ReadPeeker ¶
type Request ¶
type Request struct { Head RequestHead `json:"head"` Args []interface{} `json:"args,omitempty"` }
type RequestHead ¶
type RequestHead struct { //Type byte `json:"type"` // 0-rpc, 1-heartbeat ID uint64 `json:"id"` // ID == 0 for a heartbeat response Service string `json:"service,omitempty"` Method string `json:"method,omitempty"` Labels data.Options `json:"labels,omitempty"` Assets data.Options `json:"assets,omitempty"` // it would be send back to client }
type Response ¶
type Response struct { Head ResponseHead `json:"head"` Result Result `json:"result"` }
type ResponseHead ¶
type Result ¶
type Result struct { Value interface{} `json:"value,omitempty"` Error *errors.CodedError `json:"error,omitempty"` }
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func AutoServer ¶
AutoServer loads options from config file and create a Server.
func NewServer ¶
func NewServer(opts ServerOptions) (*Server, error)
func (*Server) RegisterFunc ¶
func (*Server) RegisterService ¶
func (*Server) Sessions ¶
func (s *Server) Sessions() SessionMap
type ServerCodec ¶
type ServerOptions ¶
type ServerOptions struct { Name string `json:"name" yaml:"name"` Desc string `json:"desc" yaml:"desc"` Version string `json:"version" yaml:"version"` Address []transport.Address Registry struct { Name string `json:"name" yaml:"name"` Options data.Map `json:"options" yaml:"options"` } `json:"registry" yaml:"registry"` CallTimeout time.Duration `json:"call_timeout" yaml:"call_timeout"` ReadTimeout time.Duration `json:"read_timeout" yaml:"read_timeout"` WriteTimeout time.Duration `json:"write_timeout" yaml:"write_timeout"` HeartbeatInterval time.Duration `json:"heartbeat_interval" yaml:"heartbeat"` MaxClients int32 `json:"max_clients" yaml:"max_clients"` MaxPoolSize int32 `json:"max_pool_size" yaml:"max_pool_size"` Backlog int32 `json:"backlog" yaml:"backlog"` Debug bool `json:"debug" yaml:"debug"` }
func (*ServerOptions) AddAddress ¶
func (opts *ServerOptions) AddAddress(uri string, options data.Map)
type SessionMap ¶
type StatusCode ¶
type StatusCode uint32
A StatusCode is an unsigned 32-bit error code.
const ( // StatusOK is returned on success. StatusOK StatusCode = 0 // StatusUnknown indicates an unknown error. An example of where this error may be returned is // if a Status value received from another address space belongs to // an error-space that is not known in this address space. Also // errors raised by APIs that do not return enough error information // may be converted to this error. StatusUnknown StatusCode = 1 // StatusCanceled indicates the operation was canceled (typically by the caller). StatusCanceled StatusCode = 2 // StatusDeadlineExceeded means operation expired before completion. // For operations that change the state of the system, this error may be // returned even if the operation has completed successfully. For // example, a successful response from a server could have been delayed // long enough for the deadline to expire. StatusDeadlineExceeded StatusCode = 3 StatusNodeUnavailable StatusCode = 4 // StatusNodeShutdown indicates Node is shut down. StatusNodeShutdown StatusCode = 5 // StatusCodecNotRegistered indicates codec is not registered. StatusCodecNotRegistered StatusCode = 6 // StatusServerClosed indicates server is closed. StatusServerClosed StatusCode = 7 // StatusMethodNotFound indicates calling method is unregistered on server. StatusMethodNotFound StatusCode = 8 // StatusInvalidArgument indicates client specified an invalid argument. // Note that this differs from FailedPrecondition. It indicates arguments // that are problematic regardless of the state of the system // (e.g., a malformed file name). StatusInvalidArgument StatusCode = 9 StatusUnauthorized StatusCode = 10 // StatusLoginFailed indicates client's login is failed. StatusLoginFailed StatusCode = 11 // StatusNilResult indicates return value is nil. StatusNilResult StatusCode = 12 )
type Stream ¶
type Stream interface { // read Reader() *bufio.Reader Peek(n int) ([]byte, error) Read(p []byte) (n int, err error) ReadByte() (byte, error) ReadBytes(delim byte) ([]byte, error) ReadString(delim byte) (string, error) // write Writer() *bufio.Writer Write(p []byte) (n int, err error) WriteByte(c byte) error WriteString(s string) (int, error) Flush() error }
Source Files ¶
Click to show internal directories.
Click to hide internal directories.