Back to

Package micro

Latest Go to latest

The latest major version is v2.

Published: Jul 3, 2020 | License: Apache-2.0 | Module:


Package micro is a pluggable framework for microservices



var (
	HeaderPrefix = "Micro-"

func NewContext

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

NewContext returns a new Context with the Service embedded within it.

func RegisterHandler

func RegisterHandler(s server.Server, h interface{}, opts ...server.HandlerOption) error

RegisterHandler is syntactic sugar for registering a handler

func RegisterSubscriber

func RegisterSubscriber(topic string, s server.Server, h interface{}, opts ...server.SubscriberOption) error

RegisterSubscriber is syntactic sugar for registering a subscriber

type Event

type Event interface {
	// Publish publishes a message to the event topic
	Publish(ctx context.Context, msg interface{}, opts ...client.PublishOption) error

Event is used to publish messages to a topic

func NewEvent

func NewEvent(topic string, c client.Client) Event

NewEvent creates a new event publisher

func NewPublisher

func NewPublisher(topic string, c client.Client) Event

Deprecated: NewPublisher returns a new Publisher

type Function

type Function interface {
	// Inherits Service interface
	// Done signals to complete execution
	Done() error
	// Handle registers an RPC handler
	Handle(v interface{}) error
	// Subscribe registers a subscriber
	Subscribe(topic string, v interface{}) error

Function is a one time executing Service

func NewFunction

func NewFunction(opts ...Option) Function

NewFunction returns a new Function for a one time executing Service

type Option

type Option func(*Options)

func Action

func Action(a func(*cli.Context) error) Option

Action can be used to parse user provided cli options

func Address

func Address(addr string) Option

Address sets the address of the server

func AfterStart

func AfterStart(fn func() error) Option

AfterStart run funcs after service starts

func AfterStop

func AfterStop(fn func() error) Option

AfterStop run funcs after service stops

func Auth

func Auth(a auth.Auth) Option

Auth sets the auth for the service

func BeforeStart

func BeforeStart(fn func() error) Option

BeforeStart run funcs before service starts

func BeforeStop

func BeforeStop(fn func() error) Option

BeforeStop run funcs before service stops

func Broker

func Broker(b broker.Broker) Option

Broker to be used for service

func Client

func Client(c client.Client) Option

Client to be used for service

func Cmd

func Cmd(c cmd.Cmd) Option

func Config

func Config(c config.Config) Option

Config sets the config for the service

func Context

func Context(ctx context.Context) Option

Context specifies a context for the service. Can be used to signal shutdown of the service and for extra option values.

func Flags

func Flags(flags ...cli.Flag) Option

Flags that can be passed to service

func HandleSignal

func HandleSignal(b bool) Option

HandleSignal toggles automatic installation of the signal handler that traps TERM, INT, and QUIT. Users of this feature to disable the signal handler, should control liveness of the service through the context.

func Metadata

func Metadata(md map[string]string) Option

Metadata associated with the service

func Name

func Name(n string) Option

Name of the service

func Profile

func Profile(p profile.Profile) Option

Profile to be used for debug profile

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

RegisterTTL specifies the TTL to use when registering the service

func Registry

func Registry(r registry.Registry) Option

Registry sets the registry for the service and the underlying components

func Runtime

func Runtime(r runtime.Runtime) Option

Runtime sets the runtime

func Selector

func Selector(s selector.Selector) Option

Selector sets the selector for the service client

func Server

func Server(s server.Server) Option

Server to be used for service

func Store

func Store(s store.Store) Option

Store sets the store to use

func Tracer

func Tracer(t trace.Tracer) Option

Tracer sets the tracer for the service

func Transport

func Transport(t transport.Transport) Option

Transport sets the transport for the service and the underlying components

func Version

func Version(v string) Option

Version of the service

func WrapCall

func WrapCall(w ...client.CallWrapper) Option

WrapCall is a convenience method for wrapping a Client CallFunc

func WrapClient

func WrapClient(w ...client.Wrapper) Option

WrapClient is a convenience method for wrapping a Client with some middleware component. A list of wrappers can be provided. Wrappers are applied in reverse order so the last is executed first.

func WrapHandler

func WrapHandler(w ...server.HandlerWrapper) Option

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

func WrapSubscriber

func WrapSubscriber(w ...server.SubscriberWrapper) Option

WrapSubscriber adds a subscriber Wrapper to a list of options passed into the server

type Options

type Options struct {
	Auth      auth.Auth
	Broker    broker.Broker
	Cmd       cmd.Cmd
	Config    config.Config
	Client    client.Client
	Server    server.Server
	Store     store.Store
	Registry  registry.Registry
	Runtime   runtime.Runtime
	Transport transport.Transport
	Profile   profile.Profile

	// Before and After funcs
	BeforeStart []func() error
	BeforeStop  []func() error
	AfterStart  []func() error
	AfterStop   []func() error

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

	Signal bool

Options for micro service

type Publisher

type Publisher = Event

Type alias to satisfy the deprecation

type Service

type Service interface {
	// The service name
	Name() string
	// Init initialises options
	// Options returns the current options
	Options() Options
	// Client is used to call services
	Client() client.Client
	// Server is for handling requests and events
	Server() server.Server
	// Run the service
	Run() error
	// The service implementation
	String() string

Service is an interface that wraps the lower level libraries within go-micro. Its a convenience method for building and initialising services.

func FromContext

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

FromContext retrieves a Service from the Context.

func NewService

func NewService(opts ...Option) Service

NewService creates and returns a new Service based on the packages within.

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier