msgprpc

package module
v0.0.0-...-06437c8 Latest Latest
Warning

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

Go to latest
Published: May 9, 2019 License: Apache-2.0 Imports: 12 Imported by: 0

README

msgprpc GoDoc Build Status

Simple msgpack-based RPC server/client with TLS support.

Install

go get github.com/OneOfOne/msgprpc

Features

  • TODO

Examples

  • TODO

License

This project is released under the Apache v2. licence. See LICENCE for more details.

Documentation

Index

Constants

View Source
const (
	Version    = 0.4
	MinVersion = 0.3

	ErrClientVersionTooLow = "client version too low"
	ErrInvalidKey          = "invalid key"
	ErrNotFound            = "endpoint not found"
)

Variables

View Source
var (
	ConnKey    = ctxKey{0}
	EncoderKey = ctxKey{1}
	DecoderKey = ctxKey{2}
)

Functions

func ConvertFromInterfaceSlice

func ConvertFromInterfaceSlice(from []interface{}, to interface{}) interface{}

ConvertFromInterfaceSlice is a helper function to convert from an `[]interface{}` slice to a typed slice. Example:

v := ConvertFromInterfaceSlice([]interface{}{1.1, 1.2, 1.3}, []float64(nil)).([]float64)

func ConvertToInterfaceSlice

func ConvertToInterfaceSlice(from interface{}) []interface{}

ConvertToInterfaceSlice is a helper function to convert a typed slice to []interface{}{} Example:

v := ConvertToInterfaceSlice([]float64{1.1, 1.2, 1.3})

func GetConn

func GetConn(ctx context.Context) net.Conn

func GetDecoder

func GetDecoder(ctx context.Context) *msgpack.Decoder

func GetEncoder

func GetEncoder(ctx context.Context) *msgpack.Encoder

func RegisterType

func RegisterType(id int8, v interface{})

RegisterType is an alias for msgpack.RegisterExt allows you to send and receive structs, the id must be the same on both the client and server

Types

type CallResult

type CallResult struct {
	Ret []interface{}
	Err error
}

type Client

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

func NewClient

func NewClient(addr, key string) *Client

func (*Client) Call

func (c *Client) Call(ctx context.Context, endpoint string, args ...interface{}) ([]interface{}, error)

func (*Client) Close

func (c *Client) Close() (err error)

type Handler

type Handler func(ctx context.Context, args ...interface{}) ([]interface{}, error)

type Server

type Server struct {
	Logger interface {
		Output(int, string) error
	}

	AuthFn func(key string) bool

	NotFoundHandler func(ctx context.Context, endpoint string, args ...interface{}) ([]interface{}, error)
	// contains filtered or unexported fields
}

func New

func New() *Server

func NewWithContext

func NewWithContext(ctx context.Context) *Server

func (*Server) Close

func (s *Server) Close() error

func (*Server) ListenAndServe

func (s *Server) ListenAndServe(addr string) error

func (*Server) ListenAndServeTLS

func (s *Server) ListenAndServeTLS(addr, cert, key string) error

func (*Server) On

func (s *Server) On(endpoint string, h Handler)

func (*Server) Serve

func (s *Server) Serve(l net.Listener) error

Jump to

Keyboard shortcuts

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