Back to godoc.org

Package datasource

v0.5.0
Latest Go to latest
Published: Jul 29, 2020 | License: Apache-2.0 | Module: github.com/alibaba/sentinel-golang

Index

Package Files

Constants

const (
	OK                  = iota
	ConvertSourceError  = 1
	UpdatePropertyError = 2
	HandleSourceError   = 3
)

func CircuitBreakerRulesJsonConverter

func CircuitBreakerRulesJsonConverter(src []byte) (interface{}, error)

func CircuitBreakerRulesUpdater

func CircuitBreakerRulesUpdater(data interface{}) error

CircuitBreakerRulesUpdater load the newest []cb.Rule to downstream circuit breaker component.

func FlowRulesJsonConverter

func FlowRulesJsonConverter(src []byte) (interface{}, error)

FlowRulesJsonConverter provide JSON as the default serialization for list of flow.FlowRule

func FlowRulesUpdater

func FlowRulesUpdater(data interface{}) error

FlowRulesUpdater load the newest []flow.FlowRule to downstream flow component.

func HotSpotParamRulesJsonConverter

func HotSpotParamRulesJsonConverter(src []byte) (interface{}, error)

HotSpotParamRulesJsonConverter decodes list of param flow rules from JSON bytes.

func HotSpotParamRulesUpdater

func HotSpotParamRulesUpdater(data interface{}) error

HotSpotParamRulesUpdater loads the provided hot-spot param rules to downstream rule manager.

func SystemRulesJsonConverter

func SystemRulesJsonConverter(src []byte) (interface{}, error)

SystemRulesJsonConverter provide JSON as the default serialization for list of system.SystemRule

func SystemRulesUpdater

func SystemRulesUpdater(data interface{}) error

SystemRulesUpdater load the newest []system.SystemRule to downstream system component.

type Base

type Base struct {
	// contains filtered or unexported fields
}

func (*Base) AddPropertyHandler

func (b *Base) AddPropertyHandler(h PropertyHandler)

func (*Base) Handle

func (b *Base) Handle(src []byte) (err error)

func (*Base) RemovePropertyHandler

func (b *Base) RemovePropertyHandler(h PropertyHandler)

type Code

type Code uint32

type DataSource

type DataSource interface {
	// Add specified property handler in current datasource
	AddPropertyHandler(h PropertyHandler)
	// Remove specified property handler in current datasource
	RemovePropertyHandler(h PropertyHandler)
	// Read original data from the data source.
	// return source bytes if succeed to read, if not, return error when reading
	ReadSource() ([]byte, error)
	// Initialize the datasource and load initial rules
	// start listener to listen on dynamic source
	// return error if initialize failed;
	// once initialized, listener should recover all panic and error.
	Initialize() error
	// Close the data source.
	io.Closer
}

The generic interface to describe the datasource Each DataSource instance listen in one property type.

type DefaultPropertyHandler

type DefaultPropertyHandler struct {
	// contains filtered or unexported fields
}

DefaultPropertyHandler encapsulate the Converter and updater of property. One DefaultPropertyHandler instance is to handle one property type. DefaultPropertyHandler should check whether current property is consistent with last update property converter convert the message to the specific property updater update the specific property to downstream.

func NewCircuitBreakerRulesHandler

func NewCircuitBreakerRulesHandler(converter PropertyConverter) *DefaultPropertyHandler

func NewDefaultPropertyHandler

func NewDefaultPropertyHandler(converter PropertyConverter, updater PropertyUpdater) *DefaultPropertyHandler

func NewSystemRulesHandler

func NewSystemRulesHandler(converter PropertyConverter) *DefaultPropertyHandler

func (*DefaultPropertyHandler) Handle

func (h *DefaultPropertyHandler) Handle(src []byte) error

type Error

type Error struct {
	// contains filtered or unexported fields
}

func NewError

func NewError(code Code, desc string) Error

func (Error) Code

func (e Error) Code() Code

func (Error) Error

func (e Error) Error() string

type MockPropertyHandler

type MockPropertyHandler struct {
	mock.Mock
}

func (*MockPropertyHandler) Handle

func (m *MockPropertyHandler) Handle(src []byte) error

type PropertyConverter

type PropertyConverter func(src []byte) (interface{}, error)

PropertyConverter func is to convert source message bytes to the specific property. the first return value: is the real property; the second return value: return nil if succeed to convert src, if not return the detailed error when convert src. if src is nil or len(src)==0, the return value is (nil,nil)

type PropertyHandler

type PropertyHandler interface {

	// handle the current property
	Handle(src []byte) error
	// contains filtered or unexported methods
}

func NewFlowRulesHandler

func NewFlowRulesHandler(converter PropertyConverter) PropertyHandler

func NewHotSpotParamRulesHandler

func NewHotSpotParamRulesHandler(converter PropertyConverter) PropertyHandler

type PropertyUpdater

type PropertyUpdater func(data interface{}) error

PropertyUpdater func is to update the specific properties to downstream. return nil if succeed to update, if not, return the error.

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

Jump to identifier

Keyboard shortcuts

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