server

package
v1.1.10 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2019 License: Apache-2.0 Imports: 13 Imported by: 7

Documentation

Overview

Package server is an interface for a micro server

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultAddress = ":0"
	DefaultName    = "go-server"
	DefaultVersion = "1.0.0"
	DefaultId      = uuid.NewUUID().String()
)

Functions

func NewContext

func NewContext(ctx context.Context, s Server) context.Context

Types

type Message

type Message interface {
	Topic() string
	Payload() interface{}
	ContentType() string
}

type Option

type Option func(*Options)

func Address

func Address(a string) Option

Address to bind to - host:port

func Advertise(a string) Option

The address to advertise for discovery - host:port

func Id

func Id(id string) Option

Unique server id

func Metadata

func Metadata(md map[string]string) Option

Metadata associated with the server

func Name

func Name(n string) Option

Server name

func RegisterInterval

func RegisterInterval(t time.Duration) Option

RegisterInterval specifies the interval on which to re-register

func RegisterTTL

func RegisterTTL(t time.Duration) Option

Register the service with a TTL

func Registry

func Registry(r registry.Registry) Option

Registry used for discovery

func Version

func Version(v string) Option

Version of the service

func Wait

func Wait(b bool) Option

Wait tells the server to wait for requests to finish before exiting

type Options

type Options struct {
	Registry  registry.Registry
	Metadata  map[string]string
	Name      string
	Address   string
	Advertise string
	Id        string
	Version   string

	RegisterInterval time.Duration
	RegisterTTL      time.Duration

	// Other options for implementations of the interface
	// can be stored in a context
	Context context.Context
}

type Request

type Request interface {
	Service() string
	Method() string
	ContentType() string
	Request() interface{}
	// indicates whether the request will be streamed
	Stream() bool
}

type Server

type Server interface {
	Options() Options
	OnInit(module module.Module, app module.App, settings *conf.ModuleSettings) error
	Init(...Option) error
	SetListener(listener mqrpc.RPCListener)
	Register(id string, f interface{})
	RegisterGO(id string, f interface{})
	ServiceRegister() error
	ServiceDeregister() error
	Start() error
	Stop() error
	OnDestroy() error
	String() string
	Id() string
}

func FromContext

func FromContext(ctx context.Context) (Server, bool)

func NewServer

func NewServer(opt ...Option) Server

NewServer returns a new server with options passed in

type Stream

type Stream interface {
	Context() context.Context
	Request() Request
	Send(interface{}) error
	Recv(interface{}) error
	Error() error
	Close() error
}

Stream represents a stream established with a client. A stream can be bidirectional which is indicated by the request. The last error will be left in Error(). EOF indicated end of the stream.

Jump to

Keyboard shortcuts

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