New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

github.com/loveholidays/go-config-loader

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/loveholidays/go-config-loader

  • v0.0.0-20241211150814-dc186d50df8d
  • Source
  • Go
  • Socket score

Version published
Created
Source

Go Config Loader

go-config-loader is a library that allows config to be read from yaml files. A common problem with reading from config files in go is ensuring required values are set. Historically there are two ways of handling this:

  1. Set up config variables as non-nullable and error if a field is set to its zero value. The issue with this is that a variable's zero value can be a valid input to an application.
  2. Set up config variables as nullable and error if a field is set to null. This solves the issue with zero values but still means every field in the config object needs to be checked. It also means code that relies on the config now has to handle nullability.

Introducing go-config-loader. The library allows the setting of a required flag in the object declaration. When the flag is set, the library will check the config yaml file for the variable and error if it isn't present. This solves the zero values issue and means there is no need to make config variables nullable. The flag is set to false by default.

The library also has the ability to interpolate environment variable values into yaml files when the variables are formatted in the way illustrated below. This can be useful for reading in secrets and sensitive content that should not be stored in version control. The api_key variable will be set to the value of MY_SECRET_API_KEY when the config is loaded.

api_key: "$MY_SECRET_API_KEY"

Getting Started

Simple Example

package main

import (
	config "github.com/loveholidays/go-config-loader"
)

type genericConfig struct {
	DummyConfig1 string `yaml:"dummy_config_1" required:"true"`
	DummyConfig2 string `yaml:"dummy_config_2"`
	DummyConfig3 string `yaml:"dummy_config_3"`
}

func main() {
	_, err := config.LoadConfiguration[genericConfig]("config.yaml")
}

FAQs

Package last updated on 11 Dec 2024

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