server

package
v0.0.0-...-7592eae Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2022 License: GPL-3.0 Imports: 12 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidType    = errors.New("type must be struct or pointer to struct")
	ErrNoSuchReceiver = errors.New("no such receiver registered")
	ErrNoSuchMethod   = errors.New("no such method was found")
	ErrInvalidMethod  = errors.New("method invalid for lrpc call")
	ErrArgNotProvided = errors.New("method expected an argument, but none was provided")
)

Functions

This section is empty.

Types

type Context

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

Context is a connection context for RPC calls

func (*Context) Deadline

func (ctx *Context) Deadline() (time.Time, bool)

Deadline always returns the current time and false as this context does not support deadlines

func (*Context) Done

func (ctx *Context) Done() <-chan struct{}

Done returns a channel that will be closed when the context is canceled, such as when ChannelDone is called by the client

func (*Context) Err

func (ctx *Context) Err() error

Err returns context.Canceled if the context was canceled, otherwise nil

func (*Context) GetCodec

func (ctx *Context) GetCodec() codec.Codec

GetCodec returns a codec bound to the connection that called this function

func (*Context) MakeChannel

func (ctx *Context) MakeChannel() (chan<- any, error)

MakeChannel changes the function it's called in into a channel function, and returns a channel which can be used to send information to the client.

This will ovewrite any return value of the function with a channel ID.

func (*Context) Value

func (ctx *Context) Value(key any) any

Value always returns nil as this context stores no values

type MethodDesc

type MethodDesc struct {
	Name    string
	Args    []string
	Returns []string
}

MethodDesc describes methods on a receiver

type Server

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

Server is an lrpc server

func New

func New() *Server

New creates and returns a new server

func (*Server) Close

func (s *Server) Close()

Close closes the server

func (*Server) Register

func (s *Server) Register(v any) error

Register registers a value to be called by a client

func (*Server) Serve

func (s *Server) Serve(ctx context.Context, ln net.Listener, cf codec.CodecFunc)

Serve starts the server using the provided listener and codec function

func (*Server) ServeConn

func (s *Server) ServeConn(ctx context.Context, conn io.ReadWriter, cf codec.CodecFunc)

ServeConn uses the provided connection to serve the client. This may be useful if something other than a net.Listener needs to be used

func (*Server) ServeWS

func (s *Server) ServeWS(ctx context.Context, addr string, cf codec.CodecFunc) (err error)

ServeWS starts a server using WebSocket. This may be useful for clients written in other languages, such as JS for a browser.

Jump to

Keyboard shortcuts

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