micro

package
v0.6.6 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewClientWrapper

func NewClientWrapper(opts ...Option) client.Wrapper

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

func WithClientResourceExtractor(fn func(context.Context, client.Request) string) Option

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

func WithServerResourceExtractor(fn func(context.Context, server.Request) string) Option

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

func WithStreamClientResourceExtractor(fn func(context.Context, client.Request) string) Option

WithStreamClientResourceExtractor sets the resource extractor of stream client request.

func WithStreamServerBlockFallback

func WithStreamServerBlockFallback(fn func(server.Stream, *base.BlockError) server.Stream) Option

WithStreamServerBlockFallback sets the block fallback handler of stream server request.

func WithStreamServerResourceExtractor

func WithStreamServerResourceExtractor(fn func(server.Stream) string) Option

WithStreamServerResourceExtractor sets the resource extractor of stream server request.

Jump to

Keyboard shortcuts

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