Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/hookactions/config

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/hookactions/config

  • v1.2.2
  • Source
  • Go
  • Socket score

Version published
Created
Source

Config

Documentation CircleCI Go Report Card license Release

Manage your application config as a typesafe struct in as little as two function calls.

package main

import (
	"context"
	"fmt"
	
	"github.com/hookactions/config"
)

type MyConfig struct {
	DatabaseUrl string `config:"DATABASE_URL"`
	FeatureFlag bool   `config:"FEATURE_FLAG"`
	Port        int // tags are optional. PORT is assumed
	...
}

var c MyConfig
config.FromEnv().To(&c)

fmt.Printf("%v\n", c)

// Supports AWS Secret Manager and Parameter store
// sm://my_value
// ssm://my_value

p, _ := config.NewAWSSecretManagerValuePreProcessor(context.Background(), true)
config.WithValuePreProcessor(p).FromEnv().To(&c)

fmt.Printf("%v\n", c)

How It Works

Its just simple, pure stdlib with optional AWS support.

  • A field's type determines what strconv function is called.

  • All string conversion rules are as defined in the strconv package

  • If chaining multiple data sources, data sets are merged. Later values override previous values.

    config.From("dev.config").FromEnv().To(&c)
    
  • Unset values remain as their native zero value

  • Nested structs/subconfigs are delimited with double underscore

    • e.g. PARENT__CHILD
  • Env vars map to struct fields case insensitively

    • NOTE: Also true when using struct tags.

Why you should use this

  • Its the cloud-native way to manage config. See 12 Factor Apps
  • Simple:
    • only 2 lines to configure.
  • Composeable:
    • Merge local files and environment variables for effortless local development.

Design Philosophy

Opinionated and narrow in scope. This library is only meant to do config binding. Feel free to use it on its own, or alongside other libraries.

  • Only structs at the entry point. This keeps the API surface small.

  • Slices are space delimited. This matches how environment variables and commandline args are handled by the go cmd.

  • No slices of structs. The extra complexity isn't warranted for such a niche usecase.

  • No maps. The only feature of maps not handled by structs for this usecase is dynamic keys.

  • No pointer members. If you really need one, just take the address of parts of your struct.

FAQs

Package last updated on 15 Jun 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc