option

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2024 License: Apache-2.0 Imports: 5 Imported by: 1

Documentation

Overview

Package option provides the Options type for plugins.

Index

Constants

This section is empty.

Variables

View Source
var EmptyOptions = newOptionsNoValidate(nil)

EmptyOptions is an instance of Options with no keys.

Functions

func GetBoolValue

func GetBoolValue(options Options, key string) (bool, error)

GetBoolValue gets a bool value from the Options.

If the value is present and is not of type bool, an error is returned.

func GetBytesValue

func GetBytesValue(options Options, key string) ([]byte, error)

GetBytesValue gets a bytes value from the Options.

If the value is present and is not of type bytes, an error is returned.

func GetFloat64SliceValue

func GetFloat64SliceValue(options Options, key string) ([]float64, error)

GetFloat64SliceValue gets a []float64 value from the Options.

If the value is present and is not of type []float64, an error is returned.

func GetFloat64Value

func GetFloat64Value(options Options, key string) (float64, error)

GetFloat64Value gets a float64 value from the Options.

If the value is present and is not of type float64, an error is returned.

func GetInt64SliceValue

func GetInt64SliceValue(options Options, key string) ([]int64, error)

GetInt64SliceValue gets a []int64 value from the Options.

If the value is present and is not of type []int64, an error is returned.

func GetInt64Value

func GetInt64Value(options Options, key string) (int64, error)

GetInt64Value gets a int64 value from the Options.

If the value is present and is not of type int64, an error is returned.

func GetStringSliceValue

func GetStringSliceValue(options Options, key string) ([]string, error)

GetStringSliceValue gets a []string value from the Options.

If the value is present and is not of type []string, an error is returned.

func GetStringValue

func GetStringValue(options Options, key string) (string, error)

GetStringValue gets a string value from the Options.

If the value is present and is not of type string, an error is returned.

Types

type Options

type Options interface {
	// Get gets the option value for the given key.
	//
	// Values will be one of:
	//
	// - int64
	// - float64
	// - string
	// - []byte
	// - bool
	// - A slice of any of the above, recursively (i.e. []string, [][]int64, ...)
	//
	// A caller should not modify a returned value.
	//
	// The key must have at least four characters.
	// The key must start and end with a lowercase letter from a-z, and only consist
	// of lowercase letters from a-z and underscores.
	Get(key string) (any, bool)
	// Range ranges over all key/value pairs.
	//
	// The range order is not deterministic.
	Range(f func(key string, value any))

	// ToProto converts the Options to its Protobuf representation.
	ToProto() ([]*optionv1.Option, error)
	// contains filtered or unexported methods
}

Options are key/values that can control the behavior of a RuleHandler, and can control the value of the Purpose string of the Rule.

For example, if you had a Rule that checked that the suffix of all Services was "API", you may want an option with key "service_suffix" that can override the suffix "API" to another suffix such as "Service". This would result in the behavior of the check changing, as well as result in the Purpose string potentially changing to specify that the expected suffix is "Service" instead of "API".

It is not possible to set a key with a not-present value. Do not add an Option with a given key to denote that the key is not set.

func NewOptions

func NewOptions(keyToValue map[string]any) (Options, error)

NewOptions returns a new validated Options for the given key/value map.

func OptionsForProtoOptions

func OptionsForProtoOptions(protoOptions []*optionv1.Option) (Options, error)

OptionsForProtoOptions returns a new Options for the given optionv1.Options.

Jump to

Keyboard shortcuts

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