reader

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: May 9, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AnyToBool

func AnyToBool(val any) (bool, bool)

typecast from any to bool

func AnyToFloat added in v0.1.1

func AnyToFloat(val any) (float64, bool)

typecast from any to float

func AnyToInt

func AnyToInt(val any) (int64, bool)

typecast from any to int

func CastSliceValue

func CastSliceValue(value any, tp reflect.Kind) ([]any, bool)

cast value to slice of type

func CastValue

func CastValue(value any, tp reflect.Kind) (any, bool)

cast value to type if needed

func FlattenMap

func FlattenMap(data map[string]any, prefix string) map[string]any

flatten nest map data to dot separated key data

func ResolveBytes

func ResolveBytes(r Reader, reader io.Reader, paths []string, strict bool) ([]byte, error)

resolve byte data from file or reader

func ResolveFileBytes

func ResolveFileBytes(r Reader, paths []string, strict bool) ([]byte, error)

resolve byte data from file

func ResolvePaths

func ResolvePaths(r Reader, opts *options.Options, path string) []string

resolve file path for config file

func ToSnakeCase

func ToSnakeCase(s string) string

convert string to snake case

Types

type BaseReader

type BaseReader struct{}

base reader to extend with (optional)

func (BaseReader) ConfigExtensions

func (r BaseReader) ConfigExtensions() []string

file extension for related reader

func (BaseReader) Parse

func (r BaseReader) Parse(_ *options.Options, _ []*Field) error

placeholder parser func since not every reader needs to parse

type Field

type Field struct {
	Name  string
	Usage string
	Value any
	Kind  reflect.Kind
	Alias []string
	List  bool
	Null  bool
}

Field definition struct for loading config

func NewField

func NewField[T any](name string, value T, usage string) (*Field, error)

Create new instance of field and resolve configs

func (*Field) AddAlias

func (f *Field) AddAlias(a string) *Field

Add field alias (e.g. env keys)

func (*Field) ValueAsBool

func (f *Field) ValueAsBool() bool

Convert value to bool

func (*Field) ValueAsInt

func (f *Field) ValueAsInt() int

Convert value to int

func (*Field) ValueAsString

func (f *Field) ValueAsString() string

Convert value to string

type Reader

type Reader interface {
	Configurator() string
	ConfigExtensions() []string
	Parse(opts *options.Options, fields []*Field) error
	Get(opts *options.Options, field *Field) (any, bool)
}

configuration reader interface

Jump to

Keyboard shortcuts

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