conman

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 5, 2020 License: GPL-3.0 Imports: 8 Imported by: 0

README

Conman

+ Tag a config to remind them to stay hydrated

Godoc reference GitHub go.mod Go version GitHub tag (latest SemVer) GitHub milestone

Quickstart

import "github.com/JoelPagliuca/conman"

var myAppConfig struct {
	Port string `cmssm:"/Prod/app/port" cmenv:"PORT" cmdefault:"8080"`
}

func init() {
	cm, _ := conman.New()
	cm.Hydrate(&myAppConfig)
}

This will try to set myAppConfig.Port to:

  • your PORT environment variable if it is set
  • your AWS SSM Parameter value set in /Prod/app/port
  • then default to 8080

Check the godoc for more

Documentation

Overview

Package conman aims to make your config setup less verbose.

This package uses `reflect` so watch out

Example

A normal use case. Will set myAppConfig.Port to:

  • your PORT environment variable if it is set
  • your AWS SSM Parameter value set in /Prod/app/port
  • then default to 8080
package main

import (
	"github.com/JoelPagliuca/conman"
)

func main() {
	var myAppConfig struct {
		Port string `cmssm:"/Prod/app/port" cmenv:"PORT" cmdefault:"8080"`
	}

	cm, _ := conman.New()
	cm.Hydrate(&myAppConfig)
}
Output:

Example (Options)
package main

import (
	"github.com/JoelPagliuca/conman"
)

func main() {
	conman.New(
		// Use APP_ as a prefix for all env values
		conman.SetEnvPrefix("APP_"),
		// Use /app-name as a prefix for all ssm names
		conman.SetSSMPrefix("/app-name"),
		// Change the ordering conman tries to load config values
		conman.SetOrder(conman.TagSSM, conman.TagEnvironment),
		// Help find out why your config wasn't loaded Properly
		conman.EnableLogging(),
		// Add a strategy to be used by Hydrate
		conman.AddStrategy(
			"cmadd",
			conman.Strategy(
				func(_ *conman.Conman, _ string) (*string, error) {
					return nil, nil
				},
			),
		),
		// Add your own `aws.Config` to be used by Hydrate
		conman.AddAWSConfig(nil),
	)
}
Output:

Index

Examples

Constants

View Source
const (
	TagEnvironment = "cmenv"
	TagSSM         = "cmssm"
	TagDefault     = "cmdefault"
)

Tags for the Hydrater to look for

Variables

This section is empty.

Functions

func DefaultStrategy

func DefaultStrategy(cm *Conman, in string) (*string, error)

DefaultStrategy sets the default defined by "in"

func EnvironmentStrategy

func EnvironmentStrategy(cm *Conman, in string) (*string, error)

EnvironmentStrategy gets the value of the environment variable "in"

func SSMStrategy added in v0.2.0

func SSMStrategy(cm *Conman, in string) (*string, error)

SSMStrategy gets the value stored in the SSM Parameter "in"

Types

type Conman

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

Conman ...

func New

func New(opts ...Option) (*Conman, error)

New sets the defaults then applies all the options

func (*Conman) Hydrate added in v0.2.0

func (cm *Conman) Hydrate(cfg interface{}) error

Hydrate - populate a config object with ssm params defined by tags. Looks for ssmConfig path from env var

type Option added in v0.2.0

type Option func(*Conman) error

Option applies some sort of option to a Conman

func AddAWSConfig added in v0.3.0

func AddAWSConfig(c *aws.Config) Option

AddAWSConfig add your own AWS config to Conman if you don't want default

func AddStrategy added in v0.2.0

func AddStrategy(tag string, str Strategy) Option

AddStrategy add a strategy to be used by the Hydrater will add it as first in the ordering

func EnableLogging added in v0.2.0

func EnableLogging() Option

EnableLogging - Log kinda interesting info

func SetEnvPrefix added in v0.3.0

func SetEnvPrefix(p string) Option

SetEnvPrefix - Hydrate will use p as a prefix for all env values

func SetOrder added in v0.2.0

func SetOrder(src ...string) Option

SetOrder choose an order to check for config in

func SetSSMPrefix added in v0.3.0

func SetSSMPrefix(p string) Option

SetSSMPrefix - Hydrate will use p as a prefix for all ssm names

type Strategy

type Strategy func(*Conman, string) (*string, error)

Strategy iface for a config getting func

Jump to

Keyboard shortcuts

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