handler

package
v2.7.1 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2022 License: Apache-2.0 Imports: 26 Imported by: 10

Documentation

Index

Constants

View Source
const (
	//consumer chain
	Transport       = "transport"
	LoadBalancing   = "loadbalance"
	Router          = "router"
	FaultInject     = "fault-inject"
	TracingConsumer = "tracing-consumer"
	TracingProvider = "tracing-provider"
)

constant keys for handlers

View Source
const (
	FaultHandlerName = "fault-inject"
)

constant for fault handler name

View Source
const (
	TrafficMarker = "traffic-marker"
)

TrafficMarker

Variables

View Source
var ChainMap = make(map[string]*Chain)

ChainMap just concurrent read

View Source
var ErrDuplicatedHandler = errors.New("duplicated handler registration")

ErrDuplicatedHandler means you registered more than 1 handler with same name

Functions

func CreateChains

func CreateChains(chainType string, handlerNameMap map[string]string) error

CreateChains create the chains based on type and handler map

func GetFaultConfig

func GetFaultConfig(protocol, microServiceName, schemaID, operationID string) model.Fault

GetFaultConfig get faultconfig

func RegisterHandler

func RegisterHandler(name string, f func() Handler) error

RegisterHandler Let developer custom handler

func WriteBackErr

func WriteBackErr(err error, status int, cb invocation.ResponseCallBack)

WriteBackErr write err and callback

Types

type Chain

type Chain struct {
	ServiceType string
	Name        string
	Handlers    []Handler
}

Chain struct for service and handlers

func CreateChain

func CreateChain(serviceType string, chainName string, handlerNames ...string) (*Chain, error)

CreateChain create consumer or provider's chain,the handlers is different

func GetChain

func GetChain(serviceType string, name string) (*Chain, error)

GetChain is to get chain

func (*Chain) AddHandler

func (c *Chain) AddHandler(h Handler)

AddHandler chain can add a handler

func (*Chain) Clone

func (c *Chain) Clone() Chain

func (*Chain) Next

Next is for to handle next handler in the chain

type ChainOption

type ChainOption func(*ChainOptions)

ChainOption is a function name

func WithChainName

func WithChainName(name string) ChainOption

WithChainName returns the name of the chain option

type ChainOptions

type ChainOptions struct {
	Name string
}

ChainOptions chain options

type FaultHandler

type FaultHandler struct{}

FaultHandler handler

func (*FaultHandler) Handle

func (rl *FaultHandler) Handle(chain *Chain, inv *invocation.Invocation, cb invocation.ResponseCallBack)

Handle is to handle the API

func (*FaultHandler) Name

func (rl *FaultHandler) Name() string

Name function returns fault-inject string

type Handler

type Handler interface {
	// handle invocation transportation,and tr response
	Handle(*Chain, *invocation.Invocation, invocation.ResponseCallBack)
	Name() string
}

Handler interface for handlers

func CreateHandler

func CreateHandler(name string) (Handler, error)

CreateHandler create a new handler by name your registered

type LBHandler

type LBHandler struct{}

LBHandler loadbalancer handler struct

func (*LBHandler) Handle

func (lb *LBHandler) Handle(chain *Chain, i *invocation.Invocation, cb invocation.ResponseCallBack)

Handle to handle the load balancing

func (*LBHandler) Name

func (lb *LBHandler) Name() string

Name returns loadbalancer string

type MarkHandler

type MarkHandler struct {
}

MarkHandler compares the match rule with invocation and mark this invocation

func (*MarkHandler) Handle

func (m *MarkHandler) Handle(chain *Chain, inv *invocation.Invocation, cb invocation.ResponseCallBack)

Handle to handle the mart invocation

func (*MarkHandler) Name

func (m *MarkHandler) Name() string

Name return the handler name

type RouterHandler

type RouterHandler struct{}

RouterHandler router handler

func (*RouterHandler) Handle

Handle is to handle the router related things

func (*RouterHandler) Name

func (ph *RouterHandler) Name() string

Name returns the router string

type TracingConsumerHandler

type TracingConsumerHandler struct{}

TracingConsumerHandler tracing consumer handler

func (*TracingConsumerHandler) Handle

Handle is handle consumer tracing related things

func (*TracingConsumerHandler) Name

func (t *TracingConsumerHandler) Name() string

Name returns tracing-consumer string

type TracingProviderHandler

type TracingProviderHandler struct{}

TracingProviderHandler tracing provider handler

func (*TracingProviderHandler) Handle

Handle is to handle the provider tracing related things

func (*TracingProviderHandler) Name

func (t *TracingProviderHandler) Name() string

Name returns tracing-provider string

Jump to

Keyboard shortcuts

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