config

package
v1.0.0-dev.63 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2024 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package config provides a wrapper around koanf.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add

func Add(key string, value interface{}, description string, opts ...Option)

Add adds a flag configuration to Entries.

func All

func All() map[string]interface{}

All returns all configs

func Bool

func Bool(path string) bool

Bool returns the bool value of a given key path or false if the path does not exist or if the value is not a valid bool representation. Accepted string representations of bool are the ones supported by strconv.ParseBool.

func BoolMap

func BoolMap(path string) map[string]bool

BoolMap returns the map[string]bool value of a given key path or an empty map[string]bool if the path does not exist or if the value is not a valid bool map.

func Bools

func Bools(path string) []bool

Bools returns the []bool slice value of a given key path or an empty []bool slice if the path does not exist or if the value is not a valid bool slice.

func Bytes

func Bytes(path string) []byte

Bytes returns the []byte value of a given key path or an empty []byte slice if the path does not exist or if the value is not a valid string.

func Duration

func Duration(path string) time.Duration

Duration returns the time.Duration value of a given key path assuming that the key contains a valid numeric value.

func Exists

func Exists(path string) bool

Exists returns true if the given key path exists in the conf map.

func Float64

func Float64(path string) float64

Float64 returns the float64 value of a given key path or 0 if the path does not exist or if the value is not a valid float64.

func Float64Map

func Float64Map(path string) map[string]float64

Float64Map returns the map[string]float64 value of a given key path or an empty map[string]float64 if the path does not exist or if the value is not a valid float64 map.

func Float64s

func Float64s(path string) []float64

Float64s returns the []float64 slice value of a given key path or an empty []float64 slice if the path does not exist or if the value is not a valid float64 slice.

func Get

func Get(path string) interface{}

Get returns interface{} value

func Int

func Int(path string) int

Int returns the int value of a given key path or 0 if the path does not exist or if the value is not a valid int.

func Int64

func Int64(path string) int64

Int64 returns the int64 value of a given key path or 0 if the path does not exist or if the value is not a valid int64.

func Int64Map

func Int64Map(path string) map[string]int64

Int64Map returns the map[string]int64 value of a given key path or an empty map[string]int64 if the path does not exist or if the value is not a valid int64 map.

func Int64s

func Int64s(path string) []int64

Int64s returns the []int64 slice value of a given key path or an empty []int64 slice if the path does not exist or if the value is not a valid int slice.

func IntMap

func IntMap(path string) map[string]int

IntMap returns the map[string]int value of a given key path or an empty map[string]int if the path does not exist or if the value is not a valid int map.

func Ints

func Ints(path string) []int

Ints returns the []int slice value of a given key path or an empty []int slice if the path does not exist or if the value is not a valid int slice.

func Load

func Load()

func MergeOptionsWithPath

func MergeOptionsWithPath[O any](opts *O, paths ...string) (*O, error)

func NewOptionsWithPath

func NewOptionsWithPath[O any](paths ...string) (opts *O, err error)

NewOptionsWithPath unmarshal options based a given multi key paths.

func Set

func Set(provider Provider)

func SetEntries

func SetEntries(v []Config)

SetEntries

func String

func String(path string) string

String returns the string value of a given key path or "" if the path does not exist or if the value is not a valid string.

func StringMap

func StringMap(path string) map[string]string

StringMap returns the map[string]string value of a given key path or an empty map[string]string if the path does not exist or if the value is not a valid string map.

func Strings

func Strings(path string) []string

Strings returns the []string slice value of a given key path or an empty []string slice if the path does not exist or if the value is not a valid string slice.

func Time

func Time(path, layout string) time.Time

Time attempts to parse the value of a given key path and return time.Time representation. If the value is numeric, it is treated as a UNIX timestamp and if it's string, a parse is attempted with the given layout.

func Unmarshal

func Unmarshal(o interface{}) error

Unmarshal unmarshals the given struct using the mapstructure lib. The whole map is unmarshalled.

func UnmarshalWithPath

func UnmarshalWithPath(path string, o interface{}) error

UnmarshalWithPath unmarshals a given key path into the given struct using the mapstructure lib.

Types

type Config

type Config struct {
	Key         string
	Value       interface{}
	Description string
	Options     *Options
}

Config represents a flag configuration.

func Entries

func Entries() []Config

Entries returns the flag configuration list as an array.

type Option

type Option func(options *Options)

Option is a func to set values in options.

func WithHide

func WithHide() Option

WithHide sets hide option is true to config.

type Options

type Options struct {
	Hide bool
}

type Provider

type Provider interface {
	Load([]Config)

	// UnmarshalWithPath unmarshals a given key path into the given struct using the mapstructure lib.
	UnmarshalWithPath(path string, o interface{}) error

	// Unmarshal unmarshals the given struct using the mapstructure lib. The whole map is unmarshalled.
	Unmarshal(o interface{}) error

	// Exists returns true if the given key path exists in the conf map.
	Exists(path string) bool

	// Int64 returns the int64 value of a given key path or 0 if the path
	// does not exist or if the value is not a valid int64.
	Int64(path string) int64

	// Int64s returns the []int64 slice value of a given key path or an
	// empty []int64 slice if the path does not exist or if the value
	// is not a valid int slice.
	Int64s(path string) []int64

	// Int64Map returns the map[string]int64 value of a given key path
	// or an empty map[string]int64 if the path does not exist or if the
	// value is not a valid int64 map.
	Int64Map(path string) map[string]int64

	// Int returns the int value of a given key path or 0 if the path
	// does not exist or if the value is not a valid int.
	Int(path string) int

	// Ints returns the []int slice value of a given key path or an
	// empty []int slice if the path does not exist or if the value
	// is not a valid int slice.
	Ints(path string) []int

	// IntMap returns the map[string]int value of a given key path
	// or an empty map[string]int if the path does not exist or if the
	// value is not a valid int map.
	IntMap(path string) map[string]int

	// Float64 returns the float64 value of a given key path or 0 if the path
	// does not exist or if the value is not a valid float64.
	Float64(path string) float64

	// Float64s returns the []float64 slice value of a given key path or an
	// empty []float64 slice if the path does not exist or if the value
	// is not a valid float64 slice.
	Float64s(path string) []float64

	// Float64Map returns the map[string]float64 value of a given key path
	// or an empty map[string]float64 if the path does not exist or if the
	// value is not a valid float64 map.
	Float64Map(path string) map[string]float64

	// Duration returns the time.Duration value of a given key path assuming
	// that the key contains a valid numeric value.
	Duration(path string) time.Duration

	// Time attempts to parse the value of a given key path and return time.Time
	// representation. If the value is numeric, it is treated as a UNIX timestamp
	// and if it's string, a parse is attempted with the given layout.
	Time(path, layout string) time.Time

	// String returns the string value of a given key path or "" if the path
	// does not exist or if the value is not a valid string.
	String(path string) string

	// Strings returns the []string slice value of a given key path or an
	// empty []string slice if the path does not exist or if the value
	// is not a valid string slice.
	Strings(path string) []string
	// StringMap returns the map[string]string value of a given key path
	// or an empty map[string]string if the path does not exist or if the
	// value is not a valid string map.
	StringMap(path string) map[string]string

	// Bytes returns the []byte value of a given key path or an empty
	// []byte slice if the path does not exist or if the value is not a valid string.
	Bytes(path string) []byte
	// Bool returns the bool value of a given key path or false if the path
	// does not exist or if the value is not a valid bool representation.
	// Accepted string representations of bool are the ones supported by strconv.ParseBool.
	Bool(path string) bool

	// Bools returns the []bool slice value of a given key path or an
	// empty []bool slice if the path does not exist or if the value
	// is not a valid bool slice.
	Bools(path string) []bool

	// BoolMap returns the map[string]bool value of a given key path
	// or an empty map[string]bool if the path does not exist or if the
	// value is not a valid bool map.
	BoolMap(path string) map[string]bool

	// All returns all configs
	All() map[string]interface{}

	// Get returns interface{} value
	Get(path string) interface{}
}

Directories

Path Synopsis
contrib
examples

Jump to

Keyboard shortcuts

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