server

package
v0.0.0-...-625ea8d Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2020 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package server is an interface for a micro server

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HandlerFunc

type HandlerFunc func(ctx context.Context, req Request, rsp interface{}) error

HandlerFunc represents a single method of a handler. It's used primarily for the wrappers. What's handed to the actual method is the concrete request and response types.

type HandlerWrapper

type HandlerWrapper func(HandlerFunc) HandlerFunc

HandlerWrapper wraps the HandlerFunc and returns the equivalent

type Option

type Option func(*Options)

Option option

func Address

func Address(a string) Option

Address to bind to - host:port

func Advertise(a string) Option

Advertise The address to advertise for discovery - host:port

func Codec

func Codec(contentType string, c codec.NewCodec) Option

Codec to use to encode/decode requests for a given content type

func ID

func ID(id string) Option

ID Unique server id

func Metadata

func Metadata(md map[string]string) Option

Metadata associated with the server

func Name

func Name(n string) Option

Name Server name

func PrivateIPBlocks

func PrivateIPBlocks(blocks string) Option

PrivateIPBlocks When Advertise is "0.0.0.0", "[::]", "::", the network segment in PrivateIPBlocks is preferentially matched. PrivateIPBlocks default value is 192.168.0.0/16. Separator is a comma (,)

func RegisterCheck

func RegisterCheck(fn func(context.Context) error) Option

RegisterCheck run func before registry service

func RegisterInterval

func RegisterInterval(t time.Duration) Option

RegisterInterval Register the service with at interval

func RegisterTTL

func RegisterTTL(t time.Duration) Option

RegisterTTL Register the service with a TTL

func Registry

func Registry(r registry.Registry) Option

Registry used for discovery

func Transport

func Transport(t transport.Transport) Option

Transport mechanism for communication e.g http, rabbitmq, etc

func Version

func Version(v string) Option

Version of the service

func WrapHandler

func WrapHandler(w HandlerWrapper) Option

WrapHandler Adds a handler Wrapper to a list of options passed into the server

type Options

type Options struct {
	Codecs          map[string]codec.NewCodec
	Registry        registry.Registry
	Transport       transport.Transport
	Metadata        map[string]string
	Name            string
	Address         string
	Advertise       string
	PrivateIPBlocks string
	ID              string
	Version         string
	HdlrWrappers    []HandlerWrapper

	// RegisterCheck runs a check function before registering the service
	RegisterCheck func(context.Context) error
	// The register expiry time
	RegisterTTL time.Duration
	// The interval on which to register
	RegisterInterval time.Duration

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

Options options

type Request

type Request interface {
	ID() string
	// The action requested
	Method() string
	// Content type provided
	ContentType() string
	// Header of the request
	Header() map[string]string
	// Body is the initial decoded value
	Body() interface{}
}

Request is a synchronous request interface

type Server

type Server interface {
	Options() Options
	Init(...Option) error
	Handle(interface{}) error
	Start() error
	Stop() error
	String() string
}

Server is a simple micro server abstraction

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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