Documentation ¶
Overview ¶
+kubebuilder:validation:Optional
Index ¶
- Constants
- Variables
- func FxLogger() func(lg *log.Logger) fxevent.Logger
- func GetBoolValue(unmarshaller Unmarshaller, key string, defaultVal bool) bool
- func GetIntValue(unmarshaller Unmarshaller, key string, defaultVal int) int
- func GetStringValue(unmarshaller Unmarshaller, key string, defaultVal string) string
- func GetValue(unmarshaller Unmarshaller, key string, defaultVal interface{}) interface{}
- func GroupTag(group string) string
- func LogModule() fx.Option
- func NameTag(name string) string
- func NewLogger(config LogConfig, w []io.Writer, isGlobalLogger bool) (*log.Logger, io.Writer)
- func RegisterDeprecatedValidator(warnOnly bool) error
- func SetDefaults(variable interface{})
- func UnmarshalJSON(bytes []byte, output interface{}) error
- func UnmarshalYAML(bytes []byte, output interface{}) error
- func ValidateStruct(rawVal interface{}) error
- type CommandLineConfig
- type CommandLineIn
- type CommandLineOut
- type ConfigFormat
- type ConfigPath
- type Duration
- type FileUnmarshallerConstructor
- type FlagSetBuilder
- type FlagSetBuilderOut
- type KoanfUnmarshaller
- func (u *KoanfUnmarshaller) Get(key string) interface{}
- func (u *KoanfUnmarshaller) IsSet(key string) bool
- func (u *KoanfUnmarshaller) Marshal() ([]byte, error)
- func (u *KoanfUnmarshaller) Reload(bytes []byte) error
- func (u *KoanfUnmarshaller) Unmarshal(i interface{}) error
- func (u *KoanfUnmarshaller) UnmarshalKey(keyPath string, i interface{}) error
- type KoanfUnmarshallerConstructor
- type LogConfig
- type LogWriterConfig
- type LoggerConstructor
- type ModuleConfig
- type ProtobufUnmarshaller
- func (u *ProtobufUnmarshaller) Get(key string) interface{}
- func (u *ProtobufUnmarshaller) IsSet(key string) bool
- func (u *ProtobufUnmarshaller) Marshal() ([]byte, error)
- func (u *ProtobufUnmarshaller) Reload(bytes []byte) error
- func (u *ProtobufUnmarshaller) Unmarshal(output interface{}) error
- func (u *ProtobufUnmarshaller) UnmarshalKey(key string, output interface{}) error
- type Time
- type Unmarshaller
Constants ¶
const ( // DefaultConfigFileExt is default config file extension. DefaultConfigFileExt = ".yaml" // DefaultKoanfDelim is default koanf delimiter. DefaultKoanfDelim = "." )
const (
// ConfigPathFlag is the name of the flag for the configuration path.
ConfigPathFlag = "config_path"
)
Variables ¶
var ( // DefaultAssetsDirectory is path to default assets directory. DefaultAssetsDirectory = path.Join("/", "etc", info.Prefix, info.Service) // DefaultLogDirectory is path to default log directory. DefaultLogDirectory = path.Join("/", "var", "log", info.Prefix, info.Service) // DefaultTempBase is path to default temporary base. DefaultTempBase = path.Join(os.TempDir(), info.Prefix, info.Service) // DefaultTempDirectory is path to default temporary directory. DefaultTempDirectory = path.Join(DefaultTempBase, guuid.NewString()) // DefaultConfigDirectory is path to default config directory. DefaultConfigDirectory = path.Join(DefaultAssetsDirectory, "config") // EnvPrefix is default environment prefix. EnvPrefix = strings.ReplaceAll(strings.ToUpper(info.Service), "-", "_") + "_" )
Functions ¶
func GetBoolValue ¶
func GetBoolValue(unmarshaller Unmarshaller, key string, defaultVal bool) bool
GetBoolValue returns the boolean value for the given key.
func GetIntValue ¶
func GetIntValue(unmarshaller Unmarshaller, key string, defaultVal int) int
GetIntValue returns the integer value for the given key.
func GetStringValue ¶
func GetStringValue(unmarshaller Unmarshaller, key string, defaultVal string) string
GetStringValue returns the string value for the given key.
func GetValue ¶
func GetValue(unmarshaller Unmarshaller, key string, defaultVal interface{}) interface{}
GetValue returns the value for the given key if config key is present.
func GroupTag ¶
GroupTag returns the group tag for the given group name in the manner of fmt.Sprintf.
func LogModule ¶
LogModule is a fx module that provides a logger and invokes setting global and standard loggers.
func NewLogger ¶
NewLogger creates a new logger instances with the provided config, and a list of additional writers.
func RegisterDeprecatedValidator ¶
RegisterDeprecatedValidator a function to validate "deprecated". If deprecated constraint exists then fail the validation.
func SetDefaults ¶
func SetDefaults(variable interface{})
SetDefaults applies the default values to the struct object, the struct type must have the StructTag with name "default" and the directed value. Example usage:
type ExampleBasic struct { Foo bool `default:"true"` Bar string `default:"33"` Qux int8 Dur time.Duration `default:"2m3s"` } foo := &ExampleBasic{} SetDefaults(foo)
func UnmarshalJSON ¶
UnmarshalJSON unmarshals using _just_ bytes as source of truth (no env, no flags, no other overrides).
func UnmarshalYAML ¶
UnmarshalYAML unmarshals using _just_ bytes as source of truth (no env, no flags, no other overrides).
func ValidateStruct ¶
func ValidateStruct(rawVal interface{}) error
ValidateStruct takes interface value and validates its fields of a struct.
Types ¶
type CommandLineConfig ¶
CommandLineConfig holds configuration for CommandLine.
func (CommandLineConfig) NewCommandLine ¶
func (config CommandLineConfig) NewCommandLine(cl CommandLineIn) (CommandLineOut, error)
NewCommandLine returns a new CommandLineOut with new FlagSet.
type CommandLineIn ¶
type CommandLineIn struct { fx.In // Builders help platform users set flags Builders []FlagSetBuilder `group:"FlagSetBuilders"` // pFlag error handling mode ErrorHandling pflag.ErrorHandling `optional:"true"` }
CommandLineIn holds parameters for NewCommandLine.
type CommandLineOut ¶
CommandLineOut holds the output of NewCommandLine, set of defined flags.
type ConfigFormat ¶
type ConfigFormat string
ConfigFormat specifies the type of the configuration format in string.
const ( // YAML is one of config formats. YAML ConfigFormat = "yaml" // JSON is one of config formats. JSON ConfigFormat = "json" )
type ConfigPath ¶
type ConfigPath struct {
Path string
}
ConfigPath stores the path to config directory for other modules to look for their config files.
type Duration ¶
type Duration struct {
// contains filtered or unexported fields
}
Duration is encoded as a string message which represents a signed span of time. It holds *durationpb.Duration which is generated type for google/protobuf/duration.proto. swagger:strfmt string +kubebuilder:validation:Type=string
func MakeDuration ¶
MakeDuration returns a new Duration.
func (*Duration) AsDuration ¶
AsDuration returns the Duration as a time.Duration.
func (*Duration) DeepCopy ¶
DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Duration.
func (*Duration) DeepCopyInto ¶
DeepCopyInto deepcopy function, copying the receiver, writing into out.
func (Duration) MarshalJSON ¶
MarshalJSON writes a Duration in JSON format.
func (*Duration) UnmarshalJSON ¶
UnmarshalJSON unmarshals and reads given bytes into a new Duration proto message.
type FileUnmarshallerConstructor ¶
type FileUnmarshallerConstructor struct { // Optional Merge Config MergeConfig map[string]interface{} // Config Name -- config file name without the extension -- it is also the annotated name of koanf instance Name string // Command line flag for reading file path PathFlag string // If flag is empty or not provided on CL, fallback to explicit path Path string // Extension of file (exact) - empty = yaml FileExt string // Enable AutomaticEnv EnableEnv bool // NoErrOnFile NoErrOnFile bool }
FileUnmarshallerConstructor holds fields to create an annotated instance of FileUnmarshaller.
func (FileUnmarshallerConstructor) Annotate ¶
func (constructor FileUnmarshallerConstructor) Annotate() fx.Option
Annotate creates an annotated instance of FileUnmarshaller.
func (FileUnmarshallerConstructor) NewFileUnmarshaller ¶
func (constructor FileUnmarshallerConstructor) NewFileUnmarshaller(flagSet *pflag.FlagSet) (Unmarshaller, ConfigPath, error)
NewFileUnmarshaller creates a new instance of FileUnmarshaller and ConfigPath that unmarshals the config file.
type FlagSetBuilder ¶
FlagSetBuilder is a function that helps users to build a Flagset.
type FlagSetBuilderOut ¶
type FlagSetBuilderOut struct { fx.Out Builder FlagSetBuilder `group:"FlagSetBuilders"` }
FlagSetBuilderOut wraps the group of FlagSetBuilder and makes it handy to provide FlagSetBuilder via Fx.
type KoanfUnmarshaller ¶
KoanfUnmarshaller backed by viper + validator + go-defaults.
func (*KoanfUnmarshaller) Get ¶
func (u *KoanfUnmarshaller) Get(key string) interface{}
Get returns an interface value for the given key path in the config map.
func (*KoanfUnmarshaller) IsSet ¶
func (u *KoanfUnmarshaller) IsSet(key string) bool
IsSet checks if the given key is set in the config map.
func (*KoanfUnmarshaller) Marshal ¶
func (u *KoanfUnmarshaller) Marshal() ([]byte, error)
Marshal returns the underlying koanf as bytes.
func (*KoanfUnmarshaller) Reload ¶
func (u *KoanfUnmarshaller) Reload(bytes []byte) error
Reload reloads the config using the underlying koanf.
func (*KoanfUnmarshaller) Unmarshal ¶
func (u *KoanfUnmarshaller) Unmarshal(i interface{}) error
Unmarshal unmarshals given i using the underlying koanf.
func (*KoanfUnmarshaller) UnmarshalKey ¶
func (u *KoanfUnmarshaller) UnmarshalKey(keyPath string, i interface{}) error
UnmarshalKey binds the given interface to the given key path in the config map and unmarshals given i using the underlying koanf with additional configuration.
type KoanfUnmarshallerConstructor ¶
type KoanfUnmarshallerConstructor struct { // Command line flags FlagSet *pflag.FlagSet // Optional Merge Config MergeConfig map[string]interface{} // Config format (yaml, json) ConfigFormat ConfigFormat // Enable AutomaticEnv EnableEnv bool }
KoanfUnmarshallerConstructor holds fields to create an annotated instance of KoanfUnmarshaller.
func (KoanfUnmarshallerConstructor) NewKoanfUnmarshaller ¶
func (constructor KoanfUnmarshallerConstructor) NewKoanfUnmarshaller(bytes []byte) (Unmarshaller, error)
NewKoanfUnmarshaller creates a new Unmarshaller instance that can be used to unmarshal configs.
type LogConfig ¶
type LogConfig struct { // Log level LogLevel string `` /* 172-byte string literal not displayed */ // Log writers Writers []LogWriterConfig `json:"writers,omitempty" validate:"omitempty,dive,omitempty"` // Use non-blocking log writer (can lose logs at high throughput) NonBlocking bool `json:"non_blocking" default:"true"` // Additional log writer: pretty console (`stdout`) logging (not recommended for prod environments) PrettyConsole bool `json:"pretty_console" default:"false"` }
LogConfig holds configuration for a logger and log writers. swagger:model +kubebuilder:object:generate=true
func (*LogConfig) DeepCopy ¶
DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LogConfig.
func (*LogConfig) DeepCopyInto ¶
DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
type LogWriterConfig ¶
type LogWriterConfig struct { // Output file for logs. Keywords allowed - [`stderr`, `default`]. `default` maps to `/var/log/fluxninja/<service>.log` File string `json:"file" default:"stderr"` // Log file max size in MB MaxSize int `json:"max_size" validate:"gte=0" default:"50"` // Max log file backups MaxBackups int `json:"max_backups" validate:"gte=0" default:"3"` // Max age in days for log files MaxAge int `json:"max_age" validate:"gte=0" default:"7"` // Compress Compress bool `json:"compress" default:"false"` }
LogWriterConfig holds configuration for a log writer. swagger:model +kubebuilder:object:generate=true
func (*LogWriterConfig) DeepCopy ¶
func (in *LogWriterConfig) DeepCopy() *LogWriterConfig
DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LogWriterConfig.
func (*LogWriterConfig) DeepCopyInto ¶
func (in *LogWriterConfig) DeepCopyInto(out *LogWriterConfig)
DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
type LoggerConstructor ¶
type LoggerConstructor struct { // Name of logger instance Name string // Config key ConfigKey string // Default Config DefaultConfig LogConfig // Global logger IsGlobal bool }
LoggerConstructor holds fields used to create an annotated instance of a logger.
func (LoggerConstructor) Annotate ¶
func (constructor LoggerConstructor) Annotate() fx.Option
Annotate creates an annotated instance of loggers which can be used to create multiple loggers.
type ModuleConfig ¶
ModuleConfig holds configuration for the config module.
func (ModuleConfig) Module ¶
func (config ModuleConfig) Module() fx.Option
Module is a fx Module that invokes CreateGlobalPanicHandlerRegistry and provides an annotated instance of CommandLine and FileUnmarshaller.
type ProtobufUnmarshaller ¶
type ProtobufUnmarshaller struct {
// contains filtered or unexported fields
}
ProtobufUnmarshaller is an unmarshaller that can unmarshalls protobuf-encoded data into messages.
No defaults handling nor validation is performed.
Note: Unmarshalling keys or unmarshalling into non-protobuf structs in not supported by this unmarshaller.
func (*ProtobufUnmarshaller) Get ¶
func (u *ProtobufUnmarshaller) Get(key string) interface{}
Get is not supported by ProtobufUnmarshaler.
func (*ProtobufUnmarshaller) IsSet ¶
func (u *ProtobufUnmarshaller) IsSet(key string) bool
IsSet is not supported by ProtobufUnmarshaler.
func (*ProtobufUnmarshaller) Marshal ¶
func (u *ProtobufUnmarshaller) Marshal() ([]byte, error)
Marshal the config into bytes.
func (*ProtobufUnmarshaller) Reload ¶
func (u *ProtobufUnmarshaller) Reload(bytes []byte) error
Reload sets the protobuf-encoded bytes.
Previous state is completely forgotten.
func (*ProtobufUnmarshaller) Unmarshal ¶
func (u *ProtobufUnmarshaller) Unmarshal(output interface{}) error
Unmarshal unmarshals previously set protobuf-encoded bytes into output.
Output should be a proto.Message.
func (*ProtobufUnmarshaller) UnmarshalKey ¶
func (u *ProtobufUnmarshaller) UnmarshalKey(key string, output interface{}) error
UnmarshalKey is not supported by ProtobufUnmarshaler.
type Time ¶
type Time struct {
// contains filtered or unexported fields
}
Time is encoded as a string message which represents a point in time independent of any time zone. It holds *timestamppb.Time which is generated types for google/protobuf/timestamp.proto. swagger:strfmt string
func (*Time) DeepCopyInto ¶
DeepCopyInto deepcopy function for Timestamp.
func (Time) MarshalJSON ¶
MarshalJSON writes a Timestamp in JSON format.
func (*Time) UnmarshalJSON ¶
UnmarshalJSON unmarshals and reads given bytes into a new Timestamp proto message.
type Unmarshaller ¶
type Unmarshaller interface { // Check whether config key is present IsSet(string) bool // Unmarshal the key into a user provided config struct UnmarshalKey(string, interface{}) error // Get specific key from config -- use cast lib to convert to bool, string etc. Get(string) interface{} // Unmarshal entire config into a struct Unmarshal(interface{}) error // Reload config Reload(bytes []byte) error // Marshal the config into bytes Marshal() ([]byte, error) }
Unmarshaller provides common interface for unmarshallers.
func NewProtobufUnmarshaller ¶
func NewProtobufUnmarshaller(bytes []byte) (Unmarshaller, error)
NewProtobufUnmarshaller crates a new ProtobufUnmarshaller.