variable

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: May 25, 2023 License: Apache-2.0 Imports: 8 Imported by: 47

Documentation

Overview

nolint

nolint

nolint

nolint

Index

Constants

View Source
const (
	ValueNotFound = "-"
)

Variables

View Source
var (
	ErrValueNotFound = errors.New("value not found")
)
View Source
var GetProtocol func(ctx context.Context) (api.ProtocolName, error)

GetProtocol returns the protocol name in the context. This allows user defines the way to get protocol. If the GetProtocol is undefined, the GetProtocolResource always returns an error.

Functions

func DefaultSetter

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

DefaultSetter used for interface-typed variable value setting

func DefaultStringSetter

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

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

Get the value of variable.

func GetProtocolResource

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

GetProtocolResource get URI,PATH,ARG var depends on ProtocolResourceName

func GetString

func GetString(ctx context.Context, v interface{}) (string, error)

GetString return the value of string-typed variable

func NewVariableContext

func NewVariableContext(ctx context.Context) context.Context

nolint

func Override added in v1.4.0

func Override(variable Variable) error

Override a variable, return error if the variable haven't been registered

func OverridePrefix added in v1.4.0

func OverridePrefix(prefix string, variable Variable) error

Override a variable with prefix, return error if the variable haven't been registered

func Register

func Register(variable Variable) error

Register a new variable

func RegisterPrefix

func RegisterPrefix(prefix string, variable Variable) error

Register a new variable with prefix

func RegisterProtocolResource

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 ResetVariableForTest

func ResetVariableForTest()

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

func Set

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

Set the value of variable.

func SetString

func SetString(ctx context.Context, v interface{}, value string) error

SetString set the value of string-typed variable

Types

type BasicVariable

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

variable.Variable

func (*BasicVariable) Data

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

Data returns variable's value

func (*BasicVariable) Getter

func (bv *BasicVariable) Getter() Getter

Getter is the variable's value get function if the variable contains it

func (*BasicVariable) Name

func (bv *BasicVariable) Name() string

Name returns variable's name

func (*BasicVariable) Setter

func (bv *BasicVariable) Setter() Setter

Setter is the variable's value set function if the variable contains it

type Getter

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

Getter used to get the value of interface-typed variable

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
	// contains filtered or unexported fields
}

IndexedValue used to store result value

type IndexedVariable

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

IndexedVariable contains index for set search

func (*IndexedVariable) GetIndex

func (iv *IndexedVariable) GetIndex() uint32

GetIndex returns the variable's index for search

func (*IndexedVariable) SetIndex

func (iv *IndexedVariable) SetIndex(index uint32)

SetIndex sets the variable's index for search

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

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

Setter used to set the value of interface-typed variable

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

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 of IndexedValue if it was not nil, Valid means the value is valid.

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

type StringSetterFunc

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{}
	// value getter
	Getter() Getter
	// value setter
	Setter() Setter
}

Variable provides a flexible and convenient way to pass information

func Check

func Check(name string) (Variable, error)

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

func NewStringVariable

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

NewStringVariable is a wrapper for NewVariable nolint:lll

func NewVariable

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

NewVariable creates a variable with name

Jump to

Keyboard shortcuts

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