server - ActiveState ActiveGo 1.8
...

Package server

import "github.com/micro/go-micro/server"
Overview
Index
Subdirectories

Overview ▾

Package server is an interface for a micro server

Index ▾

Variables
func Deregister() error
func Handle(h Handler) error
func Init(opt ...Option)
func NewContext(ctx context.Context, s Server) context.Context
func Register() error
func Run() error
func Start() error
func Stop() error
func String() string
func Subscribe(s Subscriber) error
type Debug
type Handler
    func NewHandler(h interface{}, opts ...HandlerOption) Handler
type HandlerFunc
type HandlerOption
    func EndpointMetadata(name string, md map[string]string) HandlerOption
    func InternalHandler(b bool) HandlerOption
type HandlerOptions
type HandlerWrapper
type Option
    func Address(a string) Option
    func Advertise(a string) Option
    func Broker(b broker.Broker) Option
    func Codec(contentType string, c codec.NewCodec) Option
    func DebugHandler(d debug.DebugHandler) Option
    func Id(id string) Option
    func Metadata(md map[string]string) Option
    func Name(n string) Option
    func RegisterTTL(t time.Duration) Option
    func Registry(r registry.Registry) Option
    func Transport(t transport.Transport) Option
    func Version(v string) Option
    func Wait(b bool) Option
    func WrapHandler(w HandlerWrapper) Option
    func WrapSubscriber(w SubscriberWrapper) Option
type Options
    func DefaultOptions() Options
type Publication
type Request
type Server
    func FromContext(ctx context.Context) (Server, bool)
    func NewServer(opt ...Option) Server
type Streamer
type StreamerWrapper
type Subscriber
    func NewSubscriber(topic string, h interface{}, opts ...SubscriberOption) Subscriber
type SubscriberFunc
type SubscriberOption
    func InternalSubscriber(b bool) SubscriberOption
    func SubscriberQueue(n string) SubscriberOption
type SubscriberOptions
type SubscriberWrapper

Package files

buffer.go context.go debug.go extractor.go handler.go options.go rpc_codec.go rpc_handler.go rpc_request.go rpc_server.go rpc_service.go rpc_stream.go server.go server_wrapper.go subscriber.go

Variables

var (
    DefaultAddress        = ":0"
    DefaultName           = "go-server"
    DefaultVersion        = "1.0.0"
    DefaultId             = uuid.NewUUID().String()
    DefaultServer  Server = newRpcServer()
)

func Deregister

func Deregister() error

Deregister deregisters the default server from the discovery system

func Handle

func Handle(h Handler) error

Handle registers a handler interface with the default server to handle inbound requests

func Init

func Init(opt ...Option)

Init initialises the default server with options passed in

func NewContext

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

func Register

func Register() error

Register registers the default server with the discovery system

func Run

func Run() error

Run starts the default server and waits for a kill signal before exiting. Also registers/deregisters the server

func Start

func Start() error

Start starts the default server

func Stop

func Stop() error

Stop stops the default server

func String

func String() string

String returns name of Server implementation

func Subscribe

func Subscribe(s Subscriber) error

Subscribe registers a subscriber interface with the default server which subscribes to specified topic with the broker

type Debug

We use this to wrap any debug handlers so we preserve the signature Debug.{Method}

type Debug struct {
    debug.DebugHandler
}

type Handler

Handler interface represents a Service request handler. It's generated by passing any type of public concrete object with methods into server.NewHandler. Most will pass in a struct.

Example:

type Service struct {}

func (s *Service) Method(context, request, response) error {
	return nil
}
type Handler interface {
    Name() string
    Handler() interface{}
    Endpoints() []*registry.Endpoint
    Options() HandlerOptions
}

func NewHandler

func NewHandler(h interface{}, opts ...HandlerOption) Handler

NewHandler creates a new handler interface using the default server Handlers are required to be a public object with public methods. Call to a service method such as Foo.Bar expects the type:

type Foo struct {}
func (f *Foo) Bar(ctx, req, rsp) error {
	return nil
}

type HandlerFunc

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 HandlerFunc func(ctx context.Context, req Request, rsp interface{}) error

type HandlerOption

type HandlerOption func(*HandlerOptions)

func EndpointMetadata

func EndpointMetadata(name string, md map[string]string) HandlerOption

EndpointMetadata is a Handler option that allows metadata to be added to individual endpoints.

func InternalHandler

func InternalHandler(b bool) HandlerOption

Internal Handler options specifies that a handler is not advertised to the discovery system. In the future this may also limit request to the internal network or authorised user.

type HandlerOptions

type HandlerOptions struct {
    Internal bool
    Metadata map[string]map[string]string
}

type HandlerWrapper

HandlerWrapper wraps the HandlerFunc and returns the equivalent

type HandlerWrapper func(HandlerFunc) HandlerFunc

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 Broker

func Broker(b broker.Broker) Option

Broker to use for pub/sub

func Codec

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

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

func DebugHandler

func DebugHandler(d debug.DebugHandler) Option

DebugHandler for this server

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 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 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 Wait

func Wait(b bool) Option

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

func WrapHandler

func WrapHandler(w HandlerWrapper) Option

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

func WrapSubscriber

func WrapSubscriber(w SubscriberWrapper) Option

Adds a subscriber Wrapper to a list of options passed into the server

type Options

type Options struct {
    Codecs       map[string]codec.NewCodec
    Broker       broker.Broker
    Registry     registry.Registry
    Transport    transport.Transport
    Metadata     map[string]string
    Name         string
    Address      string
    Advertise    string
    Id           string
    Version      string
    HdlrWrappers []HandlerWrapper
    SubWrappers  []SubscriberWrapper

    RegisterTTL time.Duration

    // Debug Handler which can be set by a user
    DebugHandler debug.DebugHandler

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

func DefaultOptions

func DefaultOptions() Options

DefaultOptions returns config options for the default service

type Publication

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

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
    Init(...Option) error
    Handle(Handler) error
    NewHandler(interface{}, ...HandlerOption) Handler
    NewSubscriber(string, interface{}, ...SubscriberOption) Subscriber
    Subscribe(Subscriber) error
    Register() error
    Deregister() error
    Start() error
    Stop() error
    String() 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 Streamer

Streamer 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.

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

type StreamerWrapper

StreamerWrapper wraps a Streamer interface and returns the equivalent. Because streams exist for the lifetime of a method invocation this is a convenient way to wrap a Stream as its in use for trace, monitoring, metrics, etc.

type StreamerWrapper func(Streamer) Streamer

type Subscriber

Subscriber interface represents a subscription to a given topic using a specific subscriber function or object with methods.

type Subscriber interface {
    Topic() string
    Subscriber() interface{}
    Endpoints() []*registry.Endpoint
    Options() SubscriberOptions
}

func NewSubscriber

func NewSubscriber(topic string, h interface{}, opts ...SubscriberOption) Subscriber

NewSubscriber creates a new subscriber interface with the given topic and handler using the default server

type SubscriberFunc

SubscriberFunc represents a single method of a subscriber. It's used primarily for the wrappers. What's handed to the actual method is the concrete publication message.

type SubscriberFunc func(ctx context.Context, msg Publication) error

type SubscriberOption

type SubscriberOption func(*SubscriberOptions)

func InternalSubscriber

func InternalSubscriber(b bool) SubscriberOption

Internal Subscriber options specifies that a subscriber is not advertised to the discovery system.

func SubscriberQueue

func SubscriberQueue(n string) SubscriberOption

Shared queue name distributed messages across subscribers

type SubscriberOptions

type SubscriberOptions struct {
    Queue    string
    Internal bool
}

type SubscriberWrapper

SubscriberWrapper wraps the SubscriberFunc and returns the equivalent

type SubscriberWrapper func(SubscriberFunc) SubscriberFunc

Subdirectories

Name Synopsis
..
debug
proto Package debug is a generated protocol buffer package.
mock
rpc