config

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

This file provides the Config type which can be used to populate a struct with options specified on the command line or by environment variables. Usage:

type MyConfig struct {
	StateFile           string        `desc:"File in which to store lock state" default:"" short:"s"`
	DefaultLockTimeout  time.Duration `desc:"Lock timeout to use when loading locks from state file on startup" default:"10m" short:"d"`
	NoClearOnDisconnect bool          `desc:"Do not clear locks on client disconnect" default:"false" short:"c"`
	FooSeconds          uint32        `desc:"Something" default:"10" short:"f"`
	FooInt              int           `desc:"Something" default:"100" short:"o"`
}

conf := Configure[MyConfig](&Options{
	EnvPrefix: "MYAPP_",
	Args:      os.Args[1:],
})

// `conf` fields are now populated with their defaults or values specified in
// os.Args or environment variables. Not all golang types have been implemented -
// only ones needed for ldlm.

cli argument names are converted to snake case. E.g. StateFile becomes --state_file.

environment variables must be prefixed with the envPrefix specified in Configure() and are converted to upper case snake. E.g. StateFile with an envPrefix of "MYAPP_" would be set with `MYAPP_STATE_FILE=/data/locks.state`.

Field tags:

  • desc - The description of the configuration option
  • default - The default value of the configuration option if none is specified
  • short (optional) - The short flag version of the cli option.

This file contains handlers for reflect types handled in configuration parsing

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Configure

func Configure[T any](opts *Options) *T

Configure will populate the supplied struct with options specified on the command line or by environment variables prefixed by the specified envPrefix

Types

type File

type File string

Configuration file type

type Options

type Options struct {
	EnvPrefix string
	Args      []string
}

Config options

Jump to

Keyboard shortcuts

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