protoflagz

package
v0.0.0-...-12def25 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2017 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DynProto3Value

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

DynJSONValue is a flag-related JSON struct value wrapper.

func DynProto3

func DynProto3(flagSet *flag.FlagSet, name string, value proto.Message, usage string) *DynProto3Value

DynProto3 creates a `Flag` that is backed by an arbitrary Proto3-generated datastructure which is safe to change dynamically at runtime either through JSONPB encoding or Proto encoding. The `value` must be a pointer to a struct that is JSONPB/Proto (un)marshallable. New values based on the default constructor of `value` type will be created on each update.

func (*DynProto3Value) Get

func (d *DynProto3Value) Get() proto.Message

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

func (*DynProto3Value) PrettyString

func (d *DynProto3Value) PrettyString() string

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

func (*DynProto3Value) Set

func (d *DynProto3Value) 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 (*DynProto3Value) String

func (d *DynProto3Value) String() string

String returns the canonical string representation of the type. In this case it returns the JSONPB representation of the object.

func (*DynProto3Value) Type

func (d *DynProto3Value) Type() string

Type is an indicator of what this flag represents.

func (*DynProto3Value) WithFileFlag

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

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 proto 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 (*DynProto3Value) WithNotifier

func (d *DynProto3Value) WithNotifier(notifier func(oldValue proto.Message, newValue proto.Message)) *DynProto3Value

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

func (*DynProto3Value) WithValidator

func (d *DynProto3Value) WithValidator(validator func(proto.Message) error) *DynProto3Value

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`.

Jump to

Keyboard shortcuts

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