srpc

package
v0.0.0-...-b729584 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2020 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrCodeServiceNotFound = 50001 + iota
	ErrCodeMethodNotFound
)

Variables

View Source
var DefaultGroup = "default"
View Source
var DefaultVersion = "v1.0.0"

Functions

func MakeRPCCallClient

func MakeRPCCallClient(handler InvokeFunc, coord ServiceCoordinate, v interface{}) error

MakeRPCCallClient can make a struct as a rpc client, the method is defined as fields

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(handler InvokeFunc, coordinate ServiceCoordinate) *Client

func (*Client) Call

func (cli *Client) Call(ctx context.Context, methodName string, arg interface{}, reply interface{}) error

func (*Client) Close

func (cli *Client) Close() error

type Error

type Error struct {
	StatusCode int    `json:"statusCode"`
	ErrorCode  int    `json:"code"`
	Message    string `json:"message"`
}

func ErrorOf

func ErrorOf(err error) *Error

func (Error) Error

func (e Error) Error() string

type Healthy

type Healthy interface {
	Healthy() error
}

Service can implement Healthy interface to provide service health check

type InvokeFunc

type InvokeFunc func(request *Request) (response *Response)

type Request

type Request struct {
	Coordinate ServiceCoordinate

	RequestID  string
	MethodName string

	// Client use Argument to pass argument to server
	Argument interface{}
	// Server use GetArgument to get target typed replay
	GetArgument func(out interface{}) error

	Context context.Context
}

type Response

type Response struct {
	RequestID string
	// Server use Reply to return the response to client
	Reply interface{}
	// Client use GetReply to get target typed replay
	GetReply func(out interface{}) error

	Error error

	Context context.Context
}

func ResponseOf

func ResponseOf(r *Request) *Response

type Server

type Server struct {
	// contains filtered or unexported fields
}

func NewServer

func NewServer() *Server

func (*Server) MustRegister

func (svr *Server) MustRegister(conf ServiceRegisterConf)

func (*Server) Register

func (svr *Server) Register(conf ServiceRegisterConf) error

func (*Server) ServeRequest

func (svr *Server) ServeRequest(req *Request) (resp *Response)

type ServiceCoordinate

type ServiceCoordinate struct {
	Group       string
	Version     string // semver
	PackageName string
	ServiceName string
}

func GetCoordinate

func GetCoordinate(v interface{}) ServiceCoordinate

func (ServiceCoordinate) IsValid

func (sc ServiceCoordinate) IsValid() bool

func (ServiceCoordinate) MajorVersion

func (sc ServiceCoordinate) MajorVersion() string

func (ServiceCoordinate) Normalize

func (sc ServiceCoordinate) Normalize() ServiceCoordinate

func (ServiceCoordinate) ServicePath

func (sc ServiceCoordinate) ServicePath() string

func (ServiceCoordinate) ServiceTypeName

func (sc ServiceCoordinate) ServiceTypeName() string

func (ServiceCoordinate) WithOverride

type ServiceRegisterConf

type ServiceRegisterConf struct {
	Target interface{}

	Coordinate ServiceCoordinate
}

Directories

Path Synopsis
Consul KV structure services/{group}/{service}/{version} Consul Service Structure {group}-{service.replace('.','-')}-{version}
Consul KV structure services/{group}/{service}/{version} Consul Service Structure {group}-{service.replace('.','-')}-{version}

Jump to

Keyboard shortcuts

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