Documentation ¶
Index ¶
- Constants
- Variables
- func AbortAbortAbort()
- func AppendErr(err error, errs ...error) error
- func AutoFlagsTwelveFactorCmd(name string, cmd *cobra.Command, defaults interface{}, ...) error
- func AutomaticEnv(flags *pflag.FlagSet, v *viper.Viper)
- func Decode(out Config, cfg *viper.Viper) error
- func DefineFlags(defaults interface{}) (*pflag.FlagSet, error)
- func ListenAndServe(addr string) error
- func ListenAndServeMetrics(name string, v *viper.Viper) error
- func MustDefineFlags(defaults interface{}) *pflag.FlagSet
- func NopReadCloser(r io.Reader) io.ReadCloser
- func NopWriteCloser(w io.Writer) io.WriteCloser
- func PrettyField(in interface{}, format Format) string
- func QuitQuitQuit()
- func ReadObject(r io.Reader, format Format, out interface{}) error
- func ReadObjectFrom(path string, out interface{}) error
- func TwelveFactor(name string, flags *pflag.FlagSet, viperMaybe ...*viper.Viper) error
- func TwelveFactorCmd(name string, cmd *cobra.Command, flags *pflag.FlagSet, ...) error
- func Unmarshal(out interface{}, cfg *viper.Viper) error
- func WriteObject(in interface{}, format Format, w io.Writer) error
- func WriteObjectTo(in interface{}, path string) error
- type Config
- type Format
- type Func
- type GetCronFunc
- type HasFlags
Constants ¶
const (
SquashFlagsTag = "++"
)
Variables ¶
var ( LogLevels = []string{} LogFormats = []string{"text", "json"} DefaultTimestampFormat = "2006-01-02 15:04:05.000" )
var ( JSONFormat = Format("json") YAMLFormat = Format("yaml") InputFormats = []Format{ JSONFormat, YAMLFormat, } OutputFormats = []Format{ JSONFormat, YAMLFormat, } DefaultInputFormat = YAMLFormat DefaultOutputFormat = YAMLFormat )
var (
DefaultTimeFormat = time.RFC3339
)
Functions ¶
func AbortAbortAbort ¶
func AbortAbortAbort()
func AppendErr ¶
Same as multierror.Append but takes extra care to not create non-nil multierror.Error object with no errors.n
multierror.Append(nil, nil) -> &Error{} AppendErr(nil, nil) -> nil
func AutoFlagsTwelveFactorCmd ¶
func AutoFlagsTwelveFactorCmd(name string, cmd *cobra.Command, defaults interface{}, viperMaybe ...*viper.Viper) error
Version of TwelveFactorCmd that parses flags from the provided defaults.
func AutomaticEnv ¶
Better version of viper.AutomaticEnv that searches FOO_BAR for every --foo-bar key in addition (?) to the default FOO-BAR.
Note that it must be called *after* all flags are added.
func DefineFlags ¶
Define new flags based on the provided defaults.
func ListenAndServe ¶
func MustDefineFlags ¶
Define new flags based on the provided defaults.
It panics if something goes wrong.
func NopReadCloser ¶
func NopReadCloser(r io.Reader) io.ReadCloser
NopCloser returns a ReadCloser with a no-op Close method wrapping the provided Reader r.
func NopWriteCloser ¶
func NopWriteCloser(w io.Writer) io.WriteCloser
NopCloser returns a WriteCloser with a no-op Close method wrapping the provided Writer w.
func PrettyField ¶
Simple wrapper around any object that could be used in logrus e.g.
logrus.WithField("plan", venom.PrettyField(plan)).Info("Here is the plan")
func QuitQuitQuit ¶
func QuitQuitQuit()
func ReadObjectFrom ¶
func TwelveFactor ¶
12-factor setup for viper-backed application.
Most important it will check environment variables for all flags in the provided flag set.
func TwelveFactorCmd ¶
func TwelveFactorCmd(name string, cmd *cobra.Command, flags *pflag.FlagSet, viperMaybe ...*viper.Viper) error
Configure common flags and environment config considered (by me) as a good approach to _bootstrap_ any 12-factor app.
Note that we add some extra flags & alter PreRunE value.
func WriteObjectTo ¶
Types ¶
type Config ¶
type Config interface {
Valid() error
}
Config structure that is able to self-validate.
type GetCronFunc ¶
type GetCronFunc func() *cron.Cron