parser

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrFlagsNotFound = errors.New("flags not found in cobra context")
View Source
var ErrNotUsingCobraCtx = errors.New("flag parser called without cobra context")
View Source
var FieldParsers = map[string]FieldParser{
	// contains filtered or unexported fields
}

FieldParsers is a collection of tags to parsers for the parser to use

Functions

func ParseStruct

func ParseStruct(ctx context.Context, s interface{}, failOnParseError bool) error

ParseStruct takes a struct ptr and iterates through the fields and applies any field parsers

Types

type EnvironmentParser

type EnvironmentParser struct {
}

func (EnvironmentParser) GetBoolean

func (e EnvironmentParser) GetBoolean(ctx context.Context, name string) (bool, error)

GetBoolean returns an environment variable as a boolean

func (EnvironmentParser) GetFloat

func (e EnvironmentParser) GetFloat(ctx context.Context, name string) (float64, error)

GetFloat returns an environment variable as a float

func (EnvironmentParser) GetInt

func (e EnvironmentParser) GetInt(ctx context.Context, name string) (int64, error)

GetInt returns an environment variable as an integer

func (EnvironmentParser) GetString

func (e EnvironmentParser) GetString(ctx context.Context, name string) (string, error)

GetString returns an environment variable as a string

func (EnvironmentParser) GetStringSlice

func (e EnvironmentParser) GetStringSlice(ctx context.Context, name string) ([]string, error)

type ErrEnvVariableNotFound

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

func (ErrEnvVariableNotFound) Error

func (e ErrEnvVariableNotFound) Error() string

type ErrFlagNotFound

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

func (ErrFlagNotFound) Error

func (e ErrFlagNotFound) Error() string

type FieldParser

type FieldParser interface {
	GetString(ctx context.Context, tagValue string) (string, error)
	GetInt(ctx context.Context, tagValue string) (int64, error)
	GetFloat(ctx context.Context, tagValue string) (float64, error)
	GetBoolean(ctx context.Context, tagValue string) (bool, error)
	GetStringSlice(ctx context.Context, tagValue string) ([]string, error)
}

FieldParser is an interface for fetching a field value given a tag value

type FlagParser

type FlagParser struct {
}

func (FlagParser) GetBoolean

func (p FlagParser) GetBoolean(ctx context.Context, name string) (bool, error)

GetBoolean returns a flag variable as a boolean

func (FlagParser) GetFloat

func (p FlagParser) GetFloat(ctx context.Context, name string) (float64, error)

GetFloat returns a flag variable as a float

func (FlagParser) GetInt

func (p FlagParser) GetInt(ctx context.Context, name string) (int64, error)

GetInt returns a environment variable as an integer

func (FlagParser) GetString

func (p FlagParser) GetString(ctx context.Context, name string) (string, error)

GetString returns a environment variable as a string

func (FlagParser) GetStringSlice

func (p FlagParser) GetStringSlice(ctx context.Context, name string) ([]string, error)

GetStringSlice returns a flag variable as a string slice

Jump to

Keyboard shortcuts

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