xtypes

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2023 License: GPL-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package xtypes provide additional types that can be used for configuration. All types here allow getting update from values without restarting the application. Some types may provide options for parsing or for redacting part of the value.

Index

Constants

This section is empty.

Variables

View Source
var ErrRequired = errors.New("required")

ErrRequired indicates that a required parameter was not provided.

Functions

func MustParseURL

func MustParseURL(v string) *url.URL

MustParseURL parses the URL. If parsing fails, it panics. It is being provided to make it straightforward to provide a default value to xtypes.URL, since the "url" package has only a parsing function that returns URL and error, resulting in cumbersome code, specially when needing to specify multiple default URLs.

Types

type Bool

type Bool struct {
	DefaultValue bool
	UpdateFn     func(bool)
	// contains filtered or unexported fields
}

Bool is a boolean parameter that can be updated without restarting the application. An UpdateFn must be provided to get updates for the value.

func (*Bool) GetDefaultValue

func (d *Bool) GetDefaultValue() (string, error)

GetDefaultValue will be used to read the default value when showing usage information.

func (*Bool) UnmarshalParam

func (d *Bool) UnmarshalParam(in *string) error

UnmarshalParam parses the input as a boolean.

func (*Bool) Value

func (d *Bool) Value() bool

Value reads the current updated value, taking the default value into consideration.

func (*Bool) ValueValid

func (d *Bool) ValueValid(s string) error

ValueValid test if the provided parameter value is valid. Has no side effects.

type ECDSAPrivateKey

type ECDSAPrivateKey struct {
	DefaultValue  *ecdsa.PrivateKey
	UpdateFn      func(*ecdsa.PrivateKey)
	Base64Encoder *base64.Encoding
	// contains filtered or unexported fields
}

ECDSAPrivateKey is a xtype for *ecdsa.PrivateKey.

func (*ECDSAPrivateKey) GetDefaultValue

func (d *ECDSAPrivateKey) GetDefaultValue() (string, error)

GetDefaultValue will be used to read the default value when showing usage information.

func (*ECDSAPrivateKey) RedactValue

func (d *ECDSAPrivateKey) RedactValue(string) string

RedactValue fully redacts the private key, to avoid leaking secrets.

func (*ECDSAPrivateKey) UnmarshalParam

func (d *ECDSAPrivateKey) UnmarshalParam(in *string) error

UnmarshalParam parses the input as a string.

func (*ECDSAPrivateKey) Value

func (d *ECDSAPrivateKey) Value() *ecdsa.PrivateKey

Value reads the current updated value, taking the default value into consideration. If the parameter is not marked as optional, this is guaranteed to be not nil.

func (*ECDSAPrivateKey) ValueValid

func (d *ECDSAPrivateKey) ValueValid(s string) error

ValueValid test if the provided parameter value is valid. Has no side effects.

type ECDSAPubKey

type ECDSAPubKey struct {
	DefaultValue  *ecdsa.PublicKey
	UpdateFn      func(*ecdsa.PublicKey)
	Base64Encoder *base64.Encoding
	// contains filtered or unexported fields
}

ECDSAPubKey is a xtype for values of type *ecdsa.PublicKey.

func (*ECDSAPubKey) GetDefaultValue

func (d *ECDSAPubKey) GetDefaultValue() (string, error)

GetDefaultValue will be used to read the default value when showing usage information.

func (*ECDSAPubKey) UnmarshalParam

func (d *ECDSAPubKey) UnmarshalParam(in *string) error

UnmarshalParam parses the input as a string.

func (*ECDSAPubKey) Value

func (d *ECDSAPubKey) Value() *ecdsa.PublicKey

Value reads the current updated value, taking the default value into consideration. If the parameter is not marked as optional, this is guaranteed to be not nil.

func (*ECDSAPubKey) ValueValid

func (d *ECDSAPubKey) ValueValid(s string) error

ValueValid test if the provided parameter value is valid. Has no side effects.

type Ed25519PrivateKey

type Ed25519PrivateKey struct {
	DefaultValue  ed25519.PrivateKey
	UpdateFn      func(ed25519.PrivateKey)
	Base64Encoder *base64.Encoding
	// contains filtered or unexported fields
}

Ed25519PrivateKey is a xtype for ed25519.PrivateKey.

func (*Ed25519PrivateKey) GetDefaultValue

func (d *Ed25519PrivateKey) GetDefaultValue() (string, error)

GetDefaultValue will be used to read the default value when showing usage information.

func (*Ed25519PrivateKey) RedactValue

func (d *Ed25519PrivateKey) RedactValue(string) string

RedactValue fully redacts the private key, to avoid leaking secrets.

func (*Ed25519PrivateKey) UnmarshalParam

func (d *Ed25519PrivateKey) UnmarshalParam(in *string) error

UnmarshalParam parses the input as a string.

func (*Ed25519PrivateKey) Value

Value reads the current updated value, taking the default value into consideration. If the parameter is not marked as optional, this is guaranteed to be not nil.

func (*Ed25519PrivateKey) ValueValid

func (d *Ed25519PrivateKey) ValueValid(s string) error

ValueValid test if the provided parameter value is valid. Has no side effects.

type Integer

type Integer[T constraints.Integer] struct {
	DefaultValue T
	UpdateFn     func(T)
	// contains filtered or unexported fields
}

Integer is an XType for integers.

func (*Integer[T]) GetDefaultValue

func (d *Integer[T]) GetDefaultValue() (string, error)

GetDefaultValue will be used to read the default value when showing usage information.

func (*Integer[T]) UnmarshalParam

func (d *Integer[T]) UnmarshalParam(in *string) error

UnmarshalParam parses the input as an integer of type T.

func (*Integer[T]) Value

func (d *Integer[T]) Value() T

Value reads the current updated value, taking the default value into consideration.

func (*Integer[T]) ValueValid

func (d *Integer[T]) ValueValid(s string) error

ValueValid test if the provided parameter value is valid. Has no side effects.

type OneOf

type OneOf struct {
	Choices      []string
	DefaultValue string
	IgnoreCase   bool
	UpdateFn     func(string)
	// contains filtered or unexported fields
}

OneOf is a parameter configuration that can hold a value from a list of valid options. The list of options must be provided. An UpdateFn can be provided to be notified about changes to the value.

The list of choices is mandatory, and must be provided in the "Choices" field.

If the parameter is not optional it is mandatory to provide a default value that matches one of the choices. For mandatory parameters, a default value don't have to be provided, and is ignored.

Example:

params := struct{
	Region: *xtypes.OneOf
}{
	Region: &xtypes.OneOf{
		Choices:      []string{"EU", "US"},
		DefaultValue: "EU",
	},
}

func (*OneOf) DescribeType

func (d *OneOf) DescribeType() string

DescribeType changes how usage information is shown for parameters of this type. Instead of showing the default:

{paramName}:string

this method will make it show as

{paramName}:(option1|option2|...)

func (*OneOf) GetDefaultValue

func (d *OneOf) GetDefaultValue() (string, error)

GetDefaultValue will be used to read the default value when showing usage information.

func (*OneOf) UnmarshalParam

func (d *OneOf) UnmarshalParam(in *string) error

UnmarshalParam is a custom parser for a string parameter. This will always run on brand new instance of string, so no synchronization is necessary.

func (*OneOf) Value

func (d *OneOf) Value() string

Value reads the current updated value.

func (*OneOf) ValueValid

func (d *OneOf) ValueValid(s string) error

ValueValid test if the provided parameter value is valid. Has no side effects.

type RSAPrivateKey

type RSAPrivateKey struct {
	DefaultValue  *rsa.PrivateKey
	UpdateFn      func(*rsa.PrivateKey)
	Base64Encoder *base64.Encoding
	// contains filtered or unexported fields
}

RSAPrivateKey is a xtype for values of type *rsa.PrivateKey. The key format is expected to be on PKGCS8/PEM format, optionally base64 encoded. The full value is fully redacted to avoid leaking secrets.

func (*RSAPrivateKey) GetDefaultValue

func (d *RSAPrivateKey) GetDefaultValue() (string, error)

GetDefaultValue will be used to read the default value when showing usage information.

func (*RSAPrivateKey) RedactValue

func (d *RSAPrivateKey) RedactValue(string) string

RedactValue fully redacts the secret to avoid leaking it.

func (*RSAPrivateKey) UnmarshalParam

func (d *RSAPrivateKey) UnmarshalParam(in *string) error

UnmarshalParam parses the input as a string.

func (*RSAPrivateKey) Value

func (d *RSAPrivateKey) Value() *rsa.PrivateKey

Value reads the current updated value, taking the default value into consideration. If the parameter is not marked as optional, this is guaranteed to be not nil.

func (*RSAPrivateKey) ValueValid

func (d *RSAPrivateKey) ValueValid(s string) error

ValueValid test if the provided parameter value is valid. Has no side effects.

type RawJSON

type RawJSON struct {
	DefaultValue json.RawMessage
	UpdateFn     func(*json.RawMessage)
	// contains filtered or unexported fields
}

RawJSON is a xtype for raw json messages.

func (*RawJSON) GetDefaultValue

func (d *RawJSON) GetDefaultValue() (string, error)

GetDefaultValue will be used to read the default value when showing usage information.

func (*RawJSON) UnmarshalParam

func (d *RawJSON) UnmarshalParam(in *string) error

UnmarshalParam parses the input as a string.

func (*RawJSON) Value

func (d *RawJSON) Value() json.RawMessage

Value reads the current updated value, taking the default value into consideration. If the parameter is not marked as optional, this is guaranteed to be not nil.

func (*RawJSON) ValueValid

func (d *RawJSON) ValueValid(s string) error

ValueValid test if the provided parameter value is valid. Has no side effects.

type String

type String struct {
	DefaultValue string
	UpdateFn     func(string)
	// contains filtered or unexported fields
}

String is an XType for strings.

func (*String) GetDefaultValue

func (d *String) GetDefaultValue() (string, error)

GetDefaultValue will be used to read the default value when showing usage information.

func (*String) UnmarshalParam

func (d *String) UnmarshalParam(in *string) error

UnmarshalParam parses the input as a string.

func (*String) Value

func (d *String) Value() string

Value reads the current updated value, taking the default value into consideration.

func (*String) ValueValid

func (d *String) ValueValid(s string) error

ValueValid test if the provided parameter value is valid. Has no side effects.

type URL

type URL struct {
	DefaultValue *url.URL
	UpdateFn     func(*url.URL)
	ValidateFn   func(*url.URL) error
	// contains filtered or unexported fields
}

URL is a xtype for values of type *url.URL.

func (*URL) GetDefaultValue

func (d *URL) GetDefaultValue() (string, error)

GetDefaultValue will be used to read the default value when showing usage information.

func (*URL) RedactValue

func (d *URL) RedactValue(in string) string

RedactValue is used for URLs of this type to redact themselves, avoiding leaking secrets when dumping parameter values.

func (*URL) UnmarshalParam

func (d *URL) UnmarshalParam(in *string) error

UnmarshalParam parses the input as a string.

func (*URL) Value

func (d *URL) Value() *url.URL

Value reads the current updated value, taking the default value into consideration. If the parameter is not marked as optional, this is guaranteed to be not nil.

func (*URL) ValueValid

func (d *URL) ValueValid(s string) error

ValueValid test if the provided parameter value is valid. Has no side effects.

Jump to

Keyboard shortcuts

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