conf

package
v0.4.2 Latest Latest
Warning

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

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

README

Configuration

This package is useful to load configuration values from different data sources. The lib provides a simple key-value Map with methods to fetch the loaded values. Also provides 2 loaders out of the box:

  • Yaml file loader
  • Azure AppConfig loader with Azure Key Vault integration

How to use it?

This package let you set up the configuration data sources and once that has been loaded the values can be accessed via the Map interface. For instance:

foo:
  bar:
    baz: "some config value"
package main

import (
	"fmt"
	"github.com/darksubmarine/torpedo-lib-go/conf"
)

func main() {
	// 1. Read your config from different data sources
	cfg := conf.Load(false, conf.NewYamlLoader("config.yaml"))

	// 2. Fetch values from the Map
	val := cfg.FetchStringOrElse("defaultValue", "foo", "bar", "baz")

	fmt.Println(val)

}

Documentation

Index

Constants

View Source
const (
	DEV   = "dev"
	STAGE = "stage"
	PROD  = "prod"
)

Variables

This section is empty.

Functions

func AZAppConfigFetchKeyVaultRefUri

func AZAppConfigFetchKeyVaultRefUri(value string) (string, error)

func AZParseSecretURI

func AZParseSecretURI(secretURI string) (string, string, error)

AZParseSecretURI given a secretURI returns its vaultURI (string) and secret name (string) also an error

func SlogLevel

func SlogLevel(level string) slog.Level

Types

type AZAppConfigLoader

type AZAppConfigLoader struct {
	// contains filtered or unexported fields
}

func NewAZAppConfigLoader

func NewAZAppConfigLoader(keyFilter string, labelFilter string, conn string, cred *azidentity.DefaultAzureCredential) *AZAppConfigLoader

func (*AZAppConfigLoader) AZAppConfigListSettings

func (l *AZAppConfigLoader) AZAppConfigListSettings() (map[string]string, error)

func (*AZAppConfigLoader) AZAppConfigReadSetting

func (l *AZAppConfigLoader) AZAppConfigReadSetting(value string, contentType string) (string, error)

func (*AZAppConfigLoader) AZReadSecret

func (l *AZAppConfigLoader) AZReadSecret(vaultURI string, secret string) (string, error)

AZReadSecret reads an Azure Key vault secret value given the vaultURI and the secret name.

func (*AZAppConfigLoader) Load

func (l *AZAppConfigLoader) Load(m Map) Map

type KeyVaultRef

type KeyVaultRef struct {
	Uri string `json:"uri"`
}

type Loader

type Loader interface {
	Load(m Map) Map
}

type Map

type Map map[string]interface{}

func Load

func Load(verbose bool, loaders ...Loader) Map

func (Map) Add

func (c Map) Add(val interface{}, key ...string)

func (Map) Fetch

func (c Map) Fetch(key ...string) (interface{}, bool)

func (Map) FetchBoolOrElse

func (c Map) FetchBoolOrElse(val bool, key ...string) bool

func (Map) FetchBoolP

func (c Map) FetchBoolP(key ...string) bool

func (Map) FetchIntOrElse

func (c Map) FetchIntOrElse(val int, key ...string) int

func (Map) FetchIntP

func (c Map) FetchIntP(key ...string) int

func (Map) FetchP

func (c Map) FetchP(key ...string) interface{}

func (Map) FetchStringOrElse

func (c Map) FetchStringOrElse(val string, key ...string) string

func (Map) FetchStringP

func (c Map) FetchStringP(key ...string) string

func (Map) FetchStringSliceP added in v0.3.6

func (c Map) FetchStringSliceP(key ...string) []string

func (Map) FetchSubMapP

func (c Map) FetchSubMapP(key ...string) Map

func (Map) Interpolate

func (c Map) Interpolate(verbose bool) Map

type YamlLoader

type YamlLoader struct {
	// contains filtered or unexported fields
}

func NewYamlLoader

func NewYamlLoader(filename string) *YamlLoader

func (*YamlLoader) Load

func (y *YamlLoader) Load(m Map) Map

Jump to

Keyboard shortcuts

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