paramsenc

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2023 License: MIT Imports: 7 Imported by: 1

README

status PkgGoDev

paramsenc

paramsenc implements decoding of parameters that stored in AWS Systems Manager Parameter Store.

Synopsis

See examples on pkg.go.dev.

Installation

go get github.com/aereal/paramsenc

License

See LICENSE file.

Documentation

Overview

Package paramsenc implements decoding of parameters that stored in AWS Systems Manager Parameter Store.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Unmarshal

func Unmarshal(params []types.Parameter, v interface{}) error

Types

type Decoder

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

Decoder decodes values from fetched SSM parameters.

func NewDecoder

func NewDecoder(params []types.Parameter, opts ...Option) *Decoder

NewDecoder returns a new decoder that reads from params.

func (*Decoder) Decode

func (d *Decoder) Decode(v interface{}) error

Decode decodes SSM parameters that previously given into Go values.

Supported Go value types are: - string - int family - slices

  • the element type must be also Decode()'s supported type
  • only string list parameter can be decoded

- the type implements encoding.TextUnmarshaler

Example
params := []types.Parameter{
	{Name: strRef("/str"), Type: types.ParameterTypeString, Value: strRef("strValue")},
	{Name: strRef("/int"), Type: types.ParameterTypeString, Value: strRef("64")},
	{Name: strRef("/strSlice"), Type: types.ParameterTypeStringList, Value: strRef("a,b,c")},
}
type x struct {
	Str      string   `ssmp:"/str"`
	Int      int      `ssmp:"/int"`
	StrSlice []string `ssmp:"/strSlice"`
}
var v x
if err := NewDecoder(params).Decode(&v); err != nil {
	panic(err)
}
fmt.Printf("%#v\n", v)
Output:

paramsenc.x{Str:"strValue", Int:64, StrSlice:[]string{"a", "b", "c"}}
Example (WithPathPrefix)
params := []types.Parameter{
	{Name: strRef("/my/str"), Type: types.ParameterTypeString, Value: strRef("strValue")},
	{Name: strRef("/my/int"), Type: types.ParameterTypeString, Value: strRef("64")},
	{Name: strRef("/my/strSlice"), Type: types.ParameterTypeStringList, Value: strRef("a,b,c")},
}
type x struct {
	Str      string   `ssmp:"/str"`
	Int      int      `ssmp:"/int"`
	StrSlice []string `ssmp:"/strSlice"`
}
var v x
if err := NewDecoder(params, WithPathPrefix("/my")).Decode(&v); err != nil {
	panic(err)
}
fmt.Printf("%#v\n", v)
Output:

paramsenc.x{Str:"strValue", Int:64, StrSlice:[]string{"a", "b", "c"}}

type Option

type Option func(d *Decoder)

Option is a function changes the decoder's behavior

func WithPathPrefix

func WithPathPrefix(pathPrefix string) Option

WithPathPrefix returns an Option that indicates the decoder to treat pathPrefix as common prefix.

The decoder searches corresponding parameter using its name without pathPrefix.

Jump to

Keyboard shortcuts

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