variable

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2020 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MOSN_VAR_FLAG_CHANGEABLE  = 1
	MOSN_VAR_FLAG_NOCACHEABLE = 2
	MOSN_VAR_FLAG_NOHASH      = 4

	ValueNotFound = "-"
)

Variables

This section is empty.

Functions

func BasicSetter added in v0.11.0

func BasicSetter(ctx context.Context, variableValue *IndexedValue, value string) error

BasicSetter used for variable value setting only, and would not affect any real data structure, like headers.

func GetProtocolResource added in v0.12.0

func GetProtocolResource(ctx context.Context, name api.ProtocolResourceName, data ...interface{}) (string, error)

GetProtocolResource get URI,PATH,ARG var depends on ProtocolResourceName

func GetVariableValue

func GetVariableValue(ctx context.Context, name string) (string, error)

func NewVariableContext

func NewVariableContext(ctx context.Context) context.Context

func RegisterPrefixVariable

func RegisterPrefixVariable(prefix string, variable Variable) error

func RegisterProtocolResource added in v0.12.0

func RegisterProtocolResource(protocol types.ProtocolName, resource api.ProtocolResourceName, varname string) error

RegisterProtocolResource registers the resource as ProtocolResourceName forexample protocolVar[Http1+api.URI] = http_request_uri var

func RegisterVariable

func RegisterVariable(variable Variable) error

func SetVariableValue added in v0.11.0

func SetVariableValue(ctx context.Context, name, value string) error

Types

type BasicVariable

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

variable.Variable

func (*BasicVariable) Data

func (bv *BasicVariable) Data() interface{}

func (*BasicVariable) Flags

func (bv *BasicVariable) Flags() uint32

func (*BasicVariable) Getter

func (bv *BasicVariable) Getter() GetterFunc

func (*BasicVariable) Name

func (bv *BasicVariable) Name() string

func (*BasicVariable) Setter

func (bv *BasicVariable) Setter() SetterFunc

type GetterFunc

type GetterFunc func(ctx context.Context, value *IndexedValue, data interface{}) (string, error)

GetterFunc used to get the value of variable, the implementation should handle the field (Valid, NotFound) of IndexedValue if it was not nil, Valid means the value is valid; NotFound means the value can not be found. It indicates that value can be cached for next-time get handle if any one of (Valid, NotFound) is set to true.

Function should return ValueNotFound("-") if target value not exists. E.g. reference to the header which is not existed in current request.

type IndexedValue

type IndexedValue struct {
	Valid    bool
	NotFound bool
	// contains filtered or unexported fields
}

IndexedValue used to store result value

type IndexedVariable

type IndexedVariable struct {
	BasicVariable
	// contains filtered or unexported fields
}

variable.Variable variable.VariableIndexer

func (*IndexedVariable) GetIndex

func (iv *IndexedVariable) GetIndex() uint32

func (*IndexedVariable) SetIndex

func (iv *IndexedVariable) SetIndex(index uint32)

type Indexer

type Indexer interface {
	// variable index
	GetIndex() uint32

	// set index to variable
	SetIndex(index uint32)
}

Indexer indicates that variable needs to be cached by using pre-allocated IndexedValue

type SetterFunc

type SetterFunc func(ctx context.Context, variableValue *IndexedValue, value string) error

SetterFunc used to set the value of variable

type Variable

type Variable interface {
	// variable name
	Name() string
	// variable data, which is useful for getter/setter
	Data() interface{}
	// variable flags
	Flags() uint32
	// value getter
	Getter() GetterFunc
	// value setter
	Setter() SetterFunc
}

Variable provides a flexible and convenient way to pass information

func AddVariable

func AddVariable(name string) (Variable, error)

AddVariable is used to check variable name exists. Typical usage is variables used in access logs.

func NewBasicVariable

func NewBasicVariable(name string, data interface{}, getter GetterFunc, setter SetterFunc, flags uint32) Variable

NewBasicVariable

func NewIndexedVariable

func NewIndexedVariable(name string, data interface{}, getter GetterFunc, setter SetterFunc, flags uint32) Variable

NewIndexedVariable

Jump to

Keyboard shortcuts

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