stepconf

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2023 License: MIT Imports: 9 Imported by: 68

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrNotStructPtr = errors.New("must be a pointer to a struct")

ErrNotStructPtr indicates a type is not a pointer to a struct.

Functions

func GetRangeValues

func GetRangeValues(value string) (min string, max string, minBracket string, maxBracket string, err error)

GetRangeValues reads up the given range constraint and returns the values, or an error if the constraint is malformed or could not be parsed.

func Parse

func Parse(conf interface{}) error

Parse populates a struct with the retrieved values from environment variables described by struct tags and applies the defined validations.

Example
c := struct {
	Name string `env:"ENV_NAME"`
	Num  int    `env:"ENV_NUMBER"`
}{}
if err := os.Setenv("ENV_NAME", "example"); err != nil {
	panic(err)
}
if err := os.Setenv("ENV_NUMBER", "1548"); err != nil {
	panic(err)
}
if err := Parse(&c); err != nil {
	log.Fatal(err)
}
fmt.Println(c)
Output:

{example 1548}

func Print

func Print(config interface{})

Print the name of the struct with Title case in blue color with followed by a newline, then print all fields formatted as '- field name: field value` separated by newline.

func ValidateRangeFields

func ValidateRangeFields(valueStr, constraint string) error

ValidateRangeFields validates if the given range is proper. Ranges are optional, empty values are valid.

Types

type EnvParser

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

EnvParser ...

func NewDefaultEnvParser

func NewDefaultEnvParser() EnvParser

NewDefaultEnvParser ...

func NewEnvParser

func NewEnvParser(envProvider EnvProvider) EnvParser

NewEnvParser ...

func (EnvParser) Parse

func (p EnvParser) Parse(conf interface{}) error

Parse ...

type EnvProvider

type EnvProvider interface {
	Getenv(key string) string
}

EnvProvider ...

func NewOSEnvProvider

func NewOSEnvProvider() EnvProvider

NewOSEnvProvider ...

type OSEnvProvider

type OSEnvProvider struct{}

OSEnvProvider ...

func (OSEnvProvider) Getenv

func (p OSEnvProvider) Getenv(key string) string

Getenv ...

type ParseError

type ParseError struct {
	Field string
	Value string
	Err   error
}

ParseError occurs when a struct field cannot be set.

func (*ParseError) Error

func (e *ParseError) Error() string

Error implements builtin errors.Error.

type Secret

type Secret string

Secret variables are not shown in the printed output.

func (Secret) String

func (s Secret) String() string

String implements fmt.Stringer.String. When a Secret is printed, it's masking the underlying string with asterisks.

Jump to

Keyboard shortcuts

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