Documentation ¶
Overview ¶
Package micro is a pluggable framework for microservices
Index ¶
- func NewContext(ctx context.Context, s Service) context.Context
- func RegisterHandler(s server.Server, h interface{}, opts ...server.HandlerOption) error
- func RegisterSubscriber(topic string, s server.Server, h interface{}, opts ...server.SubscriberOption) error
- type Event
- type Option
- func Action(a func(*cli.Context) error) Option
- func AddListenOption(option server.Option) Option
- func Address(addr string) Option
- func AfterStart(fn func() error) Option
- func AfterStop(fn func() error) Option
- func Auth(a auth.Auth) Option
- func BeforeStart(fn func() error) Option
- func BeforeStop(fn func() error) Option
- func Broker(b broker.Broker) Option
- func Cache(c cache.Cache) Option
- func Client(c client.Client) Option
- func Cmd(c cmd.Cmd) Option
- func Config(c config.Config) Option
- func Context(ctx context.Context) Option
- func Flags(flags ...cli.Flag) Option
- func Handle(v interface{}) Option
- func HandleSignal(b bool) Option
- func Logger(l logger.Logger) Option
- func Metadata(md map[string]string) Option
- func Name(n string) Option
- func Profile(p profile.Profile) Option
- func RegisterInterval(t time.Duration) Option
- func RegisterTTL(t time.Duration) Option
- func Registry(r registry.Registry) Option
- func Runtime(r runtime.Runtime) Option
- func Selector(s selector.Selector) Option
- func Server(s server.Server) Option
- func Store(s store.Store) Option
- func Tracer(t trace.Tracer) Option
- func Transport(t transport.Transport) Option
- func Version(v string) Option
- func WrapCall(w ...client.CallWrapper) Option
- func WrapClient(w ...client.Wrapper) Option
- func WrapHandler(w ...server.HandlerWrapper) Option
- func WrapSubscriber(w ...server.SubscriberWrapper) Option
- type Options
- type Publisher
- type Service
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewContext ¶
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.
Types ¶
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.
type Option ¶
type Option func(*Options)
func AddListenOption ¶ added in v4.8.1
Add opt to server option.
func AfterStart ¶
AfterStart run funcs after service starts.
func BeforeStart ¶
BeforeStart run funcs before service starts.
func BeforeStop ¶
BeforeStop run funcs before service stops.
func Context ¶
Context specifies a context for the service. Can be used to signal shutdown of the service and for extra option values.
func Handle ¶ added in v4.10.1
func Handle(v interface{}) Option
Handle will register a handler without any fuss
func HandleSignal ¶
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 RegisterInterval ¶
RegisterInterval specifies the interval on which to re-register.
func RegisterTTL ¶
RegisterTTL specifies the TTL to use when registering the service.
func WrapCall ¶
func WrapCall(w ...client.CallWrapper) Option
WrapCall is a convenience method for wrapping a Client CallFunc.
func WrapClient ¶
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 { Registry registry.Registry Store store.Store Auth auth.Auth Cmd cmd.Cmd Config config.Config Client client.Client Server server.Server // Other options for implementations of the interface // can be stored in a context Context context.Context Cache cache.Cache Runtime runtime.Runtime Profile profile.Profile Transport transport.Transport Logger logger.Logger Broker broker.Broker // Before and After funcs BeforeStart []func() error AfterStart []func() error AfterStop []func() error BeforeStop []func() error Signal bool }
Options for micro service.
type Service ¶
type Service interface { // The service name Name() string // Init initializes options Init(...Option) // 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 initializing services.
func FromContext ¶
FromContext retrieves a Service from the Context.
func NewService ¶
NewService creates and returns a new Service based on the packages within.