auconfigapi

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2022 License: MIT Imports: 0 Imported by: 9

README

go-autumn-config-api

API for go-autumn-config.

About go-autumn

A collection of libraries for enterprise microservices in golang that

  • is heavily inspired by Spring Boot / Spring Cloud
  • is very opinionated
  • names modules by what they do
  • unlike Spring Boot avoids certain types of auto-magical behaviour
  • is not a library monolith, that is every part only depends on the api parts of the other components at most, and the api parts do not add any dependencies.

Fall is my favourite season, so I'm calling it go-autumn.

About go-autumn-config

A library that handles configuration for enterprise microservices.

See go-autumn-config for details.

About go-autumn-config-api

This package declares a few public types that you will need for your package to collaborate with go-autumn-config. No actual code or dependencies are added if you include this package.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConfigNeedsNoValidation

func ConfigNeedsNoValidation(_ string) error

ConfigNeedsNoValidation is an empty validation function. Use this if you don't need validation for a key.

Types

type ConfigFailFunc

type ConfigFailFunc func(err error)

Type for a fatal error handler during initial configuration load. Expected to halt program execution.

Example: func fail(err error) { panic(err) }

... but you probably want to use a function from the logging package of your choice.

type ConfigItem

type ConfigItem struct {
	// Where in the configuration structure the config item resides.
	//
	// Hierarchical levels are separated by '.', key components should match [a-z][a-z0-9-]*
	// that is, stick to lowercase letters and possibly - sign.
	//
	// Examples: "server.host",
	//           "server.port",
	//           "profiles"
	Key string

	// Default value that also specifies the type of the value.
	//
	// You must always specify a value that has a type, or else detection of types will not work.
	// That is, "" is ok, nil is not. Numeric types need a type specifier such as int32(-10).
	//
	// You can also specify a struct type, but note that for values inside struct types, command line
	// flags are not supported.
	//
	// Examples: "localhost",
	//           uint(8080),
	//           []string{}  (for a list of strings),
	//           SomeStructDefinedInMyCode{SomeField: "someDefaultValue"}
	Default interface{}

	// A human readable description.
	//
	// Examples: "The hostname or ip address that determines the interface to listen on, defaults to localhost",
	//           "The port your main web controller should listen on. Defaults to 8080",
	//           "The list of profiles to load",
	Description string

	// Override name for environment variable (optional)
	//
	// If left blank, defaults to CONFIG_ + uppercase key with all non [a-z0-9] replaced with _.
	EnvName string

	// Override name for the command line flag (optional)
	//
	// If left blank, defaults to the key.
	FlagName string

	// Validation function that should return an error if the validation failed
	//
	// You MUST provide one, but you can just use ConfigNeedsNoValidation
	Validate ConfigValidationFunc
}

ConfigItem represents a configuration item for go-autumn-config.

When you call auconfig.Setup(...) with a list of these, it will configure a command line flag and an environment variable.

When you request configuration to be loaded, which you must do yourself with a call to auconfig.Load(), every key is assigned its value by going through the following precedence list:

  • command line flag
  • environment variable
  • configuration read from secrets.(yaml|json|properties)
  • configuration read from the config-[profile].(yaml|json|properties|...) in reverse order
  • configuration read from config.(yaml|json|properties)
  • default value specified in ConfigItems

type ConfigValidationFunc

type ConfigValidationFunc func(key string) error

ConfigValidationFunc is the type for a config item validation function.

Important: note that you are given the KEY of the config item. This avoids having to use interface{} here, so you won't have to do type casting. Instead, just look up the value with viper.GetString(key), or viper.GetUint(key), ... (if using go-autumn-config), or auconfigenv.Get(key) (if using go-autumn-config-env).

type ConfigWarnFunc

type ConfigWarnFunc func(message string)

Type for a warning message logging handler during configuration load and validation. Should not halt execution.

Example: func warn(message string) { log.Printf(message) }

... but you probably want to use a function from the logging package of your choice.

Jump to

Keyboard shortcuts

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