Skip to content
This repository has been archived by the owner on Apr 24, 2023. It is now read-only.

gofor-little/cfg

Repository files navigation

A package for loading config data from AWS SecretsManager

GitHub tag (latest SemVer pre-release) GitHub go.mod Go version License: MIT GitHub Workflow Status Go Report Card PkgGoDev

Introduction

  • Secure config loading.
  • Support AWS SecretsManager.
  • Easy JSON unmarshaling into a struct.

Example

package main

import (
	"context"

	"github.com/gofor-little/cfg"
)

type Config struct {
	SomeStringValue string `json:"someStringValue"`
	SomeIntValue    int    `json:"someIntValue"`
}

func main() {
	// Initialize the cfg package.
	if err := cfg.Initialize(context.Background(), "AWS_PROFILE", "AWS_REGION"); err != nil {
		panic(err)
	}

	// Load and parse the config data into the passed Config struct.
	config := &Config{}
	if err := cfg.Load(context.Background(), "AWS_SECRET_ARN", config); err != nil {
		panic(err)
	}
}

Testing

Ensure the following environment variables are set, usually with a .env file.

  • AWS_PROFILE (an AWS CLI profile name)
  • AWS_REGION (a valid AWS region)

Run go test -v ./... in the root directory.