Documentation ¶
Overview ¶
This package provides Sentinel integration for go-micro.
For server side, users may append a Sentinel handler wrapper to go-micro service, like:
import ( sentinelPlugin "github.com/brucewangzhihua/sentinel-golang/adapter/micro" ) // Append a Sentinel handler wrapper. micro.NewService(micro.WrapHandler(sentinelPlugin.NewHandlerWrapper()))
The plugin extracts service method as the resource name by default. Users may provide customized resource name extractor when creating new Sentinel handler wrapper (via options).
Fallback logic: the plugin will return the BlockError by default if current request is blocked by Sentinel rules. Users may also provide customized fallback logic via WithXxxBlockFallback(handler) options.
Index ¶
- func NewClientWrapper(opts ...Option) client.Wrapper
- func NewHandlerWrapper(sentinelOpts ...Option) server.HandlerWrapper
- func NewStreamWrapper(sentinelOpts ...Option) server.StreamWrapper
- type Option
- func WithClientBlockFallback(fn func(context.Context, client.Request, *base.BlockError) error) Option
- func WithClientResourceExtractor(fn func(context.Context, client.Request) string) Option
- func WithServerBlockFallback(fn func(context.Context, server.Request, *base.BlockError) error) Option
- func WithServerResourceExtractor(fn func(context.Context, server.Request) string) Option
- func WithStreamClientBlockFallback(...) Option
- func WithStreamClientResourceExtractor(fn func(context.Context, client.Request) string) Option
- func WithStreamServerBlockFallback(fn func(server.Stream, *base.BlockError) server.Stream) Option
- func WithStreamServerResourceExtractor(fn func(server.Stream) string) Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewClientWrapper ¶
NewClientWrapper returns a sentinel client Wrapper.
func NewHandlerWrapper ¶
func NewHandlerWrapper(sentinelOpts ...Option) server.HandlerWrapper
NewHandlerWrapper returns a Handler Wrapper with Alibaba Sentinel breaker
func NewStreamWrapper ¶
func NewStreamWrapper(sentinelOpts ...Option) server.StreamWrapper
Types ¶
type Option ¶
type Option func(*options)
func WithClientBlockFallback ¶
func WithClientBlockFallback(fn func(context.Context, client.Request, *base.BlockError) error) Option
WithUnaryClientBlockFallback sets the block fallback handler of unary client request. The second string parameter is the full method name of current invocation.
func WithClientResourceExtractor ¶
WithUnaryClientResourceExtractor sets the resource extractor of unary client request. The second string parameter is the full method name of current invocation.
func WithServerBlockFallback ¶
func WithServerBlockFallback(fn func(context.Context, server.Request, *base.BlockError) error) Option
WithUnaryServerBlockFallback sets the block fallback handler of unary server request.
func WithServerResourceExtractor ¶
WithUnaryServerResourceExtractor sets the resource extractor of unary server request.
func WithStreamClientBlockFallback ¶
func WithStreamClientBlockFallback(fn func(context.Context, client.Request, *base.BlockError) (client.Stream, error)) Option
WithStreamClientBlockFallback sets the block fallback handler of stream client request.
func WithStreamClientResourceExtractor ¶
WithStreamClientResourceExtractor sets the resource extractor of stream client request.
func WithStreamServerBlockFallback ¶
WithStreamServerBlockFallback sets the block fallback handler of stream server request.