conf

package module
v0.0.0-...-7d23870 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2023 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package conf provides a way to get configuration from multiple sources, using a single struct to define the fields.

Index

Constants

View Source
const Required required = true

Variables

View Source
var (
	JSON format = format{[]string{".json"}, json.Marshal, json.Unmarshal}
	XML  format = format{[]string{".xml"}, xml.Marshal, xml.Unmarshal}
	TOML format = format{[]string{".toml"}, toml.Marshal, toml.Unmarshal}
	YAML format = format{[]string{".yaml", ".yml"}, yaml.Marshal, yaml.Unmarshal}
)
View Source
var ColumnDefault = tableColumn{/* contains filtered or unexported fields */}
View Source
var ColumnEnv = tableColumn{/* contains filtered or unexported fields */}
View Source
var ColumnFlag = tableColumn{/* contains filtered or unexported fields */}
View Source
var ColumnFlagShort = tableColumn{/* contains filtered or unexported fields */}
View Source
var ColumnJSON = tableColumn{/* contains filtered or unexported fields */}
View Source
var ColumnName = tableColumn{/* contains filtered or unexported fields */}
View Source
var ColumnUsage = tableColumn{/* contains filtered or unexported fields */}
View Source
var DefaultTableColumns = []tableColumn{
	ColumnName,
	ColumnDefault,
	ColumnUsage,
}
View Source
var FileEnv = FilesEnv()
View Source
var OSEnv environSource = environSource(os.Environ)

Functions

func BaseName

func BaseName(n string) fileOptFn

func ConfigPaths

func ConfigPaths(appName string) fileOptErrFn

ConfigPaths causes a file read to pull from the OS-specific configuration directory.

func FilesEnv

func FilesEnv(filenames ...string) environSource

func Flags

func Flags(dst any, opts ...flagOpt) *flag.FlagSet

func LoadEnv

func LoadEnv(dst any, opts ...envOpt) error

LoadEnv populates dst with configuration from the environment.

func LoadFile

func LoadFile(dst any, opts ...fileOpt) error

func Must

func Must(err error)

func PFlags

func PFlags(dst any, opts ...flagOpt) *pflag.FlagSet

func Paths

func Paths(paths ...string) fileOptFn

func SaveFile

func SaveFile(obj any, filename string, format format) error

Types

type Documentation

type Documentation struct {
	Name   string
	Fields []*Field
}

func Help

func Help(dst any) *Documentation

func (*Documentation) Markdown

func (d *Documentation) Markdown(columns ...tableColumn) string

func (*Documentation) String

func (d *Documentation) String() string

func (*Documentation) WriteToTable

func (d *Documentation) WriteToTable(table *tablewriter.Table, columns ...tableColumn)

type Field

type Field struct {
	Name string
	Tags reflect.StructTag
	Ptr  any
	// contains filtered or unexported fields
}

func (*Field) EnvName

func (f *Field) EnvName() string

func (*Field) FlagName

func (f *Field) FlagName() (long, short string)

func (*Field) String

func (f *Field) String() string

func (*Field) Tag

func (f *Field) Tag(name string) string

func (*Field) Usage

func (f *Field) Usage() string

type URL

type URL url.URL

func ParseURL

func ParseURL(s string) (*URL, error)

func (URL) MarshalText

func (u URL) MarshalText() ([]byte, error)

func (*URL) String

func (u *URL) String() string

func (*URL) UnmarshalText

func (u *URL) UnmarshalText(b []byte) error

Jump to

Keyboard shortcuts

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