go-flagz: github.com/mwitkow/go-flagz Index | Files | Directories

package flagz

import "github.com/mwitkow/go-flagz"

Index

Package Files

checksum.go common.go dynduration.go dynfloat64.go dynint64.go dynjson.go dynstring.go dynstringset.go dynstringslice.go endpoint.go fileread_flag.go

func ChecksumFlagSet Uses

func ChecksumFlagSet(flagSet *pflag.FlagSet, flagFilter func(flag *pflag.Flag) bool) []byte

ChecksumFlagSet will generate a FNV of the *set* values in a FlagSet.

func IsFlagDynamic Uses

func IsFlagDynamic(f *flag.Flag) bool

IsFlagDynamic returns whether the given Flag has been created in a Dynamic mode.

func MarkFlagDynamic Uses

func MarkFlagDynamic(f *flag.Flag)

MarkFlagDynamic marks the flag as Dynamic and changeable at runtime.

func ReadFileFlags Uses

func ReadFileFlags(flagSet *flag.FlagSet) error

ReadFileFlags parses the flagset to discover all "fileread" flags and evaluates them.

By reading and evaluating it means: attempts to read the file and set the value.

func ValidateDynFloat64Range Uses

func ValidateDynFloat64Range(fromInclusive float64, toInclusive float64) func(float64) error

ValidateDynFloat64Range returns a validator that checks if the float value is in range.

func ValidateDynInt64Range Uses

func ValidateDynInt64Range(fromInclusive int64, toInclusive int64) func(int64) error

ValidateDynInt64Range returns a validator function that checks if the integer value is in range.

func ValidateDynStringMatchesRegex Uses

func ValidateDynStringMatchesRegex(matcher *regexp.Regexp) func(string) error

ValidateDynStringMatchesRegex returns a validator function that checks all flag's values against regex.

func ValidateDynStringSetMinElements Uses

func ValidateDynStringSetMinElements(count int) func(map[string]struct{}) error

ValidateDynStringSetMinElements validates that the given string slice has at least x elements.

func ValidateDynStringSliceMinElements Uses

func ValidateDynStringSliceMinElements(count int) func([]string) error

ValidateDynStringSliceMinElements validates that the given string slice has at least x elements.

type DynDurationValue Uses

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

DynDurationValue is a flag-related `time.Duration` value wrapper.

func DynDuration Uses

func DynDuration(flagSet *flag.FlagSet, name string, value time.Duration, usage string) *DynDurationValue

DynDuration creates a `Flag` that represents `time.Duration` which is safe to change dynamically at runtime.

func (*DynDurationValue) Get Uses

func (d *DynDurationValue) Get() time.Duration

Get retrieves the value in a thread-safe manner.

func (*DynDurationValue) Set Uses

func (d *DynDurationValue) Set(input string) error

Set updates the value from a string representation in a thread-safe manner. This operation may return an error if the provided `input` doesn't parse, or the resulting value doesn't pass an optional validator. If a notifier is set on the value, it will be invoked in a separate go-routine.

func (*DynDurationValue) String Uses

func (d *DynDurationValue) String() string

String represents the canonical representation of the type.

func (*DynDurationValue) Type Uses

func (d *DynDurationValue) Type() string

Type is an indicator of what this flag represents.

func (*DynDurationValue) WithNotifier Uses

func (d *DynDurationValue) WithNotifier(notifier func(oldValue time.Duration, newValue time.Duration)) *DynDurationValue

WithNotifier adds a function is called every time a new value is successfully set. Each notifier is executed in a new go-routine.

func (*DynDurationValue) WithValidator Uses

func (d *DynDurationValue) WithValidator(validator func(time.Duration) error) *DynDurationValue

WithValidator adds a function that checks values before they're set. Any error returned by the validator will lead to the value being rejected. Validators are executed on the same go-routine as the call to `Set`.

type DynFloat64Value Uses

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

DynFloat64Value is a flag-related `float64` value wrapper.

func DynFloat64 Uses

func DynFloat64(flagSet *flag.FlagSet, name string, value float64, usage string) *DynFloat64Value

DynFloat64 creates a `Flag` that represents `float64` which is safe to change dynamically at runtime.

func (*DynFloat64Value) Get Uses

func (d *DynFloat64Value) Get() float64

Get retrieves the value in a thread-safe manner.

func (*DynFloat64Value) Set Uses

func (d *DynFloat64Value) Set(input string) error

Set updates the value from a string representation in a thread-safe manner. This operation may return an error if the provided `input` doesn't parse, or the resulting value doesn't pass an optional validator. If a notifier is set on the value, it will be invoked in a separate go-routine.

func (*DynFloat64Value) String Uses

func (d *DynFloat64Value) String() string

String returns the canonical string representation of the type.

func (*DynFloat64Value) Type Uses

func (d *DynFloat64Value) Type() string

Type is an indicator of what this flag represents.

func (*DynFloat64Value) WithNotifier Uses

func (d *DynFloat64Value) WithNotifier(notifier func(oldValue float64, newValue float64)) *DynFloat64Value

WithNotifier adds a function is called every time a new value is successfully set. Each notifier is executed in a new go-routine.

func (*DynFloat64Value) WithValidator Uses

func (d *DynFloat64Value) WithValidator(validator func(float64) error) *DynFloat64Value

WithValidator adds a function that checks values before they're set. Any error returned by the validator will lead to the value being rejected. Validators are executed on the same go-routine as the call to `Set`.

type DynInt64Value Uses

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

DynInt64Value is a flag-related `int64` value wrapper.

func DynInt64 Uses

func DynInt64(flagSet *flag.FlagSet, name string, value int64, usage string) *DynInt64Value

DynInt64 creates a `Flag` that represents `int64` which is safe to change dynamically at runtime.

func (*DynInt64Value) Get Uses

func (d *DynInt64Value) Get() int64

Get retrieves the value in a thread-safe manner.

func (*DynInt64Value) Set Uses

func (d *DynInt64Value) Set(input string) error

Set updates the value from a string representation in a thread-safe manner. This operation may return an error if the provided `input` doesn't parse, or the resulting value doesn't pass an optional validator. If a notifier is set on the value, it will be invoked in a separate go-routine.

func (*DynInt64Value) String Uses

func (d *DynInt64Value) String() string

String returns the canonical string representation of the type.

func (*DynInt64Value) Type Uses

func (d *DynInt64Value) Type() string

Type is an indicator of what this flag represents.

func (*DynInt64Value) WithNotifier Uses

func (d *DynInt64Value) WithNotifier(notifier func(oldValue int64, newValue int64)) *DynInt64Value

WithNotifier adds a function is called every time a new value is successfully set. Each notifier is executed in a new go-routine.

func (*DynInt64Value) WithValidator Uses

func (d *DynInt64Value) WithValidator(validator func(int64) error) *DynInt64Value

WithValidator adds a function that checks values before they're set. Any error returned by the validator will lead to the value being rejected. Validators are executed on the same go-routine as the call to `Set`.

type DynJSONValue Uses

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

DynJSONValue is a flag-related JSON struct value wrapper.

func DynJSON Uses

func DynJSON(flagSet *flag.FlagSet, name string, value interface{}, usage string) *DynJSONValue

DynJSON creates a `Flag` that is backed by an arbitrary JSON which is safe to change dynamically at runtime. The `value` must be a pointer to a struct that is JSON (un)marshallable. New values based on the default constructor of `value` type will be created on each update.

func (*DynJSONValue) Get Uses

func (d *DynJSONValue) Get() interface{}

Get retrieves the value in its original JSON struct type in a thread-safe manner.

func (*DynJSONValue) PrettyString Uses

func (d *DynJSONValue) PrettyString() string

PrettyString returns a nicely structured representation of the type. In this case it returns a pretty-printed JSON.

func (*DynJSONValue) Set Uses

func (d *DynJSONValue) Set(input string) error

Set updates the value from a string representation in a thread-safe manner. This operation may return an error if the provided `input` doesn't parse, or the resulting value doesn't pass an optional validator. If a notifier is set on the value, it will be invoked in a separate go-routine.

func (*DynJSONValue) String Uses

func (d *DynJSONValue) String() string

String returns the canonical string representation of the type.

func (*DynJSONValue) Type Uses

func (d *DynJSONValue) Type() string

Type is an indicator of what this flag represents.

func (*DynJSONValue) WithFileFlag Uses

func (d *DynJSONValue) WithFileFlag(defaultPath string) *DynJSONValue

WithFileFlag adds an companion <name>_path flag that allows this value to be read from a file with flagz.ReadFileFlags.

This is useful for reading large JSON files as flags. If the companion flag's value (whether default or overwritten) is set to empty string, nothing is read.

Flag value reads are subject to notifiers and validators.

func (*DynJSONValue) WithNotifier Uses

func (d *DynJSONValue) WithNotifier(notifier func(oldValue interface{}, newValue interface{})) *DynJSONValue

WithNotifier adds a function is called every time a new value is successfully set. Each notifier is executed in a new go-routine.

func (*DynJSONValue) WithValidator Uses

func (d *DynJSONValue) WithValidator(validator func(interface{}) error) *DynJSONValue

WithValidator adds a function that checks values before they're set. Any error returned by the validator will lead to the value being rejected. Validators are executed on the same go-routine as the call to `Set`.

type DynStringSetValue Uses

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

DynStringSetValue is a flag-related `map[string]struct{}` value wrapper.

func DynStringSet Uses

func DynStringSet(flagSet *flag.FlagSet, name string, value []string, usage string) *DynStringSetValue

DynStringSet creates a `Flag` that represents `map[string]struct{}` which is safe to change dynamically at runtime. Unlike `pflag.StringSlice`, consecutive sets don't append to the slice, but override it.

func (*DynStringSetValue) Contains Uses

func (d *DynStringSetValue) Contains(val string) bool

Contains returns whether the specified string is in the flag.

func (*DynStringSetValue) Get Uses

func (d *DynStringSetValue) Get() map[string]struct{}

Get retrieves the value in a thread-safe manner.

func (*DynStringSetValue) Set Uses

func (d *DynStringSetValue) Set(val string) error

Set updates the value from a string representation in a thread-safe manner. This operation may return an error if the provided `input` doesn't parse, or the resulting value doesn't pass an optional validator. If a notifier is set on the value, it will be invoked in a separate go-routine.

func (*DynStringSetValue) String Uses

func (d *DynStringSetValue) String() string

String represents the canonical representation of the type.

func (*DynStringSetValue) Type Uses

func (d *DynStringSetValue) Type() string

Type is an indicator of what this flag represents.

func (*DynStringSetValue) WithNotifier Uses

func (d *DynStringSetValue) WithNotifier(notifier func(oldValue map[string]struct{}, newValue map[string]struct{})) *DynStringSetValue

WithNotifier adds a function that is called every time a new value is successfully set. Each notifier is executed asynchronously in a new go-routine.

func (*DynStringSetValue) WithValidator Uses

func (d *DynStringSetValue) WithValidator(validator func(map[string]struct{}) error) *DynStringSetValue

WithValidator adds a function that checks values before they're set. Any error returned by the validator will lead to the value being rejected. Validators are executed on the same go-routine as the call to `Set`.

type DynStringSliceValue Uses

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

DynStringSliceValue is a flag-related `time.Duration` value wrapper.

func DynStringSlice Uses

func DynStringSlice(flagSet *flag.FlagSet, name string, value []string, usage string) *DynStringSliceValue

DynStringSlice creates a `Flag` that represents `[]string` which is safe to change dynamically at runtime. Unlike `pflag.StringSlice`, consecutive sets don't append to the slice, but override it.

func (*DynStringSliceValue) Get Uses

func (d *DynStringSliceValue) Get() []string

Get retrieves the value in a thread-safe manner.

func (*DynStringSliceValue) Set Uses

func (d *DynStringSliceValue) Set(val string) error

Set updates the value from a string representation in a thread-safe manner. This operation may return an error if the provided `input` doesn't parse, or the resulting value doesn't pass an optional validator. If a notifier is set on the value, it will be invoked in a separate go-routine.

func (*DynStringSliceValue) String Uses

func (d *DynStringSliceValue) String() string

String represents the canonical representation of the type.

func (*DynStringSliceValue) Type Uses

func (d *DynStringSliceValue) Type() string

Type is an indicator of what this flag represents.

func (*DynStringSliceValue) WithNotifier Uses

func (d *DynStringSliceValue) WithNotifier(notifier func(oldValue []string, newValue []string)) *DynStringSliceValue

WithNotifier adds a function that is called every time a new value is successfully set. Each notifier is executed asynchronously in a new go-routine.

func (*DynStringSliceValue) WithValidator Uses

func (d *DynStringSliceValue) WithValidator(validator func([]string) error) *DynStringSliceValue

WithValidator adds a function that checks values before they're set. Any error returned by the validator will lead to the value being rejected. Validators are executed on the same go-routine as the call to `Set`.

type DynStringValue Uses

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

DynStringValue is a flag-related `time.Duration` value wrapper.

func DynString Uses

func DynString(flagSet *flag.FlagSet, name string, value string, usage string) *DynStringValue

DynString creates a `Flag` that represents `string` which is safe to change dynamically at runtime.

func (*DynStringValue) Get Uses

func (d *DynStringValue) Get() string

Get retrieves the value in a thread-safe manner.

func (*DynStringValue) Set Uses

func (d *DynStringValue) Set(val string) error

Set updates the value from a string representation in a thread-safe manner. This operation may return an error if the provided `input` doesn't parse, or the resulting value doesn't pass an optional validator. If a notifier is set on the value, it will be invoked in a separate go-routine.

func (*DynStringValue) String Uses

func (d *DynStringValue) String() string

String represents the canonical representation of the type.

func (*DynStringValue) Type Uses

func (d *DynStringValue) Type() string

Type is an indicator of what this flag represents.

func (*DynStringValue) WithNotifier Uses

func (d *DynStringValue) WithNotifier(notifier func(oldValue string, newValue string)) *DynStringValue

WithNotifier adds a function is called every time a new value is successfully set. Each notifier is executed in a new go-routine.

func (*DynStringValue) WithValidator Uses

func (d *DynStringValue) WithValidator(validator func(string) error) *DynStringValue

WithValidator adds a function that checks values before they're set. Any error returned by the validator will lead to the value being rejected. Validators are executed on the same go-routine as the call to `Set`.

type FileReadValue Uses

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

FileReadValue is a flag that wraps another flag and makes it readable from a local file in the filesystem.

func FileReadFlag Uses

func FileReadFlag(flagSet *flag.FlagSet, parentFlagName string, defaultFilePath string) *FileReadValue

FileReadFlag creates a `Flag` that allows you to pass a flag.

If defaultFilePath is non empty, the flagz.ReadFileFlags will expect the file to be there.

func (*FileReadValue) Set Uses

func (f *FileReadValue) Set(path string) error

func (*FileReadValue) String Uses

func (f *FileReadValue) String() string

func (*FileReadValue) Type Uses

func (f *FileReadValue) Type() string

type StatusEndpoint Uses

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

StatusEndpoint is a collection of `http.HandlerFunc` that serve debug pages about a given `FlagSet.

func NewStatusEndpoint Uses

func NewStatusEndpoint(flagSet *flag.FlagSet) *StatusEndpoint

NewStatusEndpoint creates a new debug `http.HandlerFunc` collection for a given `FlagSet`

func (*StatusEndpoint) ListFlags Uses

func (e *StatusEndpoint) ListFlags(resp http.ResponseWriter, req *http.Request)

ListFlags provides an HTML and JSON `http.HandlerFunc` that lists all Flags of a `FlagSet`. Additional URL query parameters can be used such as `type=[dynamic,static]` or `only_changed=true`.

Directories

PathSynopsis
configmap
monitoring
protobuf
watcher

Package flagz imports 17 packages (graph) and is imported by 10 packages. Updated 2017-04-13. Refresh now. Tools for package owners.