figgy

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2019 License: Apache-2.0 Imports: 12 Imported by: 0

README

go-figgy

GoDoc CircleCI codecov Go Report Card

Why is this a thing?!

We wanted to experiment with AWS's Parameter Store as a centralized system for managing out configurations. Turns out, it is a lot of work loading them and pushing the values into configuration structs to be used by other components.

Our solution was to use Go's awesome tag feature to ease the burden of using the SSM SDK directly. This allows us to define our configuration in the struct itself and populate the struct's fields with values when loaded!

TLDR: Tags are awesome and injecting configuration from AWS into our structs with them is even awesomer!

Install

go get github.com/Syncbak-Git/go-figgy

Getting started

It's as simple as defining a struct, decorating it with tags, and loading it.

type Config struct{
    Server   string `ssm:"/myapp/prod/server"`
    Port     int    `ssm:"/myapp/prod/port"`
    Password string `ssm:"/myapp/prod/password,decrypt"`
}

//... meanwhile, more handwaving
cfg := Config{}
figgy.Load(ssmClient, &cfg)

Runtime parameters

You can have a parameter defined at runtime by using the LoadWithParameters function:

type Config struct{
    Server   string `ssm:"/myapp/{{.env}}/server"`
    Port     int    `ssm:"/myapp/{{.env}}/port"`
    Password string `ssm:"/myapp/{{.env}}/password,decrypt"`
}

cfg := Config{}
figgy.LoadWithParameters(ssmClient, &cfg, figgy.P{"env": "prod"})

Using Server as an example, this will be computed to a key of /myapp/prod/server at runtime.

The Future

Here are some additional features we would like to see in the near future:

  • Support type conversions for map type and slices of structs
  • Allow tags defined on a parent struct to influence the child field tags
    • This is similar to how the xml package handles unmarshaling

Documentation

Overview

Package figgy provides tags for loading parameters from AWS Parameter Store

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Load

func Load(c ssmiface.SSMAPI, v interface{}) error

Load AWS Parameter Store parameters based on the defined tags.

When a source type is an array, it is assumed the parameter being loaded is a comma separated list. The list will be split and converted to match the array's typing.

You can ignore a field by using "-" for a fields tag. Unexported fields are also ignored.

func LoadWithParameters

func LoadWithParameters(c ssmiface.SSMAPI, v interface{}, data interface{}) error

LoadWithParameters loads AWS Parameter Store parameters based on the defined tags, performing parameter substitution on field tags using data-driven templates from "text/template".

When a source type is an array, it is assumed the parameter being loaded is a comma separated list. The list will be split and converted to match the array's typing.

You can ignore a field by using "-" for a fields tag. Unexported fields are also ignored.

Types

type ConvertTypeError

type ConvertTypeError struct {
	//Field that the value was being assigned to
	Field string
	// Type of value that couldn't be assigned
	Type string
	// Value that failed to be converted
	Value string
}

ConvertTypeError describes a value that failed to be set for a field

func (*ConvertTypeError) Error

func (e *ConvertTypeError) Error() string

type InvalidTypeError

type InvalidTypeError struct {
	Type reflect.Type
}

InvalidTypeError descibes an invalid argument passed to Load.

func (*InvalidTypeError) Error

func (e *InvalidTypeError) Error() string

type P added in v1.1.0

type P map[string]interface{}

P is a convenience alias for passing paramters to LoadWithParameters

type TagParseError

type TagParseError struct {
	// Tag that failed to be fully parsed
	Tag string
	// Field metadata that the tag is parsed from
	Field string
}

TagParseError describes an invalid tag

func (*TagParseError) Error

func (e *TagParseError) Error() string

type Unmarshaler

type Unmarshaler interface {
	UnmarshalParameter(string) error
}

Jump to

Keyboard shortcuts

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