conf

package
v1.19.3 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2023 License: LGPL-3.0 Imports: 13 Imported by: 0

README

Overview

Package conf is a framework for reading configurations from variety of configuration stores, such as ENV, files, or Apollo.

Supported Stores

  • ENV
  • Local files
  • Apollo. Watching is also supported

Supported Formats

  • properties, props, prop
  • json
  • yaml, yml
  • toml
  • hcl
  • tfvars
  • ini
  • env
  • dotenv

Examples

Please refer HERE for examples.

Documentation

Overview

Package conf is a framework for reading configurations from variety of configuration Stores, such as ENV, files, and Apollo.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithDecodeHook added in v1.19.3

func WithDecodeHook(hook DecodeHook) option

WithDecodeHook sets a user-defined decoder

func WithStores

func WithStores(stores ...store.Store) option

WithStores sets Stores to ConfigParser

func WithTagName

func WithTagName(tag string) option

WithTagName sets tag name used when unmarshalling data to the configuration struct. Default is mapstructure

Types

type ConfigParser

type ConfigParser[T any] struct {
	// contains filtered or unexported fields
}

ConfigParser is a configuration data parser. It supports variety of configuration Stores, mainstream configuration formats, watching, and templates

  • `T` is the struct for unmarshalling configuration data

func New

func New[T any](opts ...option) *ConfigParser[T]

New creates a ConfigParser object

  • T is the struct for unmarshalling configuration data

func (*ConfigParser[T]) Parse

func (c *ConfigParser[T]) Parse() (*T, error)

Parse reads configuration data from all Stores, then unmarshal it to `T`.

func (*ConfigParser[T]) Unwatch

func (c *ConfigParser[T]) Unwatch()

Unwatch stops watching

func (*ConfigParser[T]) Watch

func (c *ConfigParser[T]) Watch(cb func(cfg *T, changes []store.ConfigChange)) error

Watch watches configuration changes from all Stores, unmarshal the latest configuration data into `T`, then notify the caller via `cb`

type DecodeHook

type DecodeHook func(to reflect.Type, data string) (interface{}, error)

DecodeHook decodes `data` to an object of type `to`. It returns the decoded value as interface{} on success, otherwise, an error is returned.

Directories

Path Synopsis
Package store defines the Store interface, some common types and some common functions.
Package store defines the Store interface, some common types and some common functions.
apollo
Package apollo implements Store for reading and watching configurations from Apollo.
Package apollo implements Store for reading and watching configurations from Apollo.
env
Package env implements a Store for reading and watching configurations from ENV.
Package env implements a Store for reading and watching configurations from ENV.
file
Package file implements a Store client for reading and watching configurations from local files.
Package file implements a Store client for reading and watching configurations from local files.
Package tdata implements TemplateData from which data can be used to replace templates from other Stores.
Package tdata implements TemplateData from which data can be used to replace templates from other Stores.

Jump to

Keyboard shortcuts

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