variable

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2022 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 deprecated added in v0.11.0

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

Deprecated: use DefaultStringSetter or DefaultSetter instead

func DefaultSetter added in v0.24.0

func DefaultSetter(ctx context.Context, variableValue *IndexedValue, value interface{}) error

DefaultSetter used for interface-typed variable value setting

func DefaultStringSetter added in v0.24.0

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

DefaultStringSetter used for string-typed variable value setting only, and would not affect any real data structure, like headers.

func Get added in v0.24.0

func Get(ctx context.Context, name string) (interface{}, error)

Get the value of variable

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 GetString added in v0.24.0

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

GetString return the value of string-typed variable

func GetVariableValue deprecated

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

Deprecated: use Get or GetString instead

func NewVariableContext

func NewVariableContext(ctx context.Context) context.Context

func Register added in v0.24.0

func Register(variable Variable) error

Register a new variable

func RegisterPrefix added in v0.24.0

func RegisterPrefix(prefix string, variable Variable) error

Register a new variable with prefix

func RegisterPrefixVariable deprecated

func RegisterPrefixVariable(prefix string, variable Variable) error

Deprecated: use RegisterPrefix instead

func RegisterProtocolResource added in v0.12.0

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

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

func RegisterVariable deprecated

func RegisterVariable(variable Variable) error

Deprecated: use Register instead

func ResetVariableForTest added in v0.22.0

func ResetVariableForTest()

ResetVariableForTest is a test function for reset the variables. DONOT call it in any non-test functions

func Set added in v0.24.0

func Set(ctx context.Context, name string, value interface{}) error

Set the value of variable

func SetString added in v0.24.0

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

SetString set the value of string-typed variable

func SetVariableValue deprecated added in v0.11.0

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

Deprecated: use Set or SetString instead

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() Getter

func (*BasicVariable) Name

func (bv *BasicVariable) Name() string

func (*BasicVariable) Setter

func (bv *BasicVariable) Setter() Setter

type Getter added in v0.24.0

type Getter interface {
	Get(ctx context.Context, value *IndexedValue, data interface{}) (interface{}, error)
}

type GetterFunc

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

GetterFunc used to get the value of interface-typed variable

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 Setter added in v0.24.0

type Setter interface {
	Set(ctx context.Context, variableValue *IndexedValue, value interface{}) error
}

type SetterFunc

type SetterFunc func(ctx context.Context, variableValue *IndexedValue, value interface{}) error

SetterFunc used to set the value of interface-typed variable

type StringGetterFunc added in v0.24.0

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

StringGetterFunc used to get the value of string-typed 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 StringSetterFunc added in v0.24.0

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

StringSetterFunc used to set the value of string-typed 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() Getter
	// value setter
	Setter() Setter
}

Variable provides a flexible and convenient way to pass information

func AddVariable deprecated

func AddVariable(name string) (Variable, error)

Deprecated: AddVariable is used to check variable name exists. Typical usage is variables used in access logs. use Check instead

func Check added in v0.24.0

func Check(name string) (Variable, error)

Check return the variable related to name, return error if not registered

func NewBasicVariable deprecated

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

Deprecated: use NewStringVariable instead.

func NewIndexedVariable deprecated

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

Deprecated: use NewStringVariable instead.

func NewStringVariable added in v0.24.0

func NewStringVariable(name string, data interface{}, getter StringGetterFunc, setter StringSetterFunc, flags uint32) Variable

func NewVariable added in v0.24.0

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

Jump to

Keyboard shortcuts

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