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

github.com/Noah-Huppert/goconf

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/Noah-Huppert/goconf

  • v0.2.3
  • Source
  • Go
  • Socket score

Version published
Created
Source

Goconf Go Doc

Simple go configuration library.

Table Of Contents

Overview

Goconf is a simple, straightforward, go configuration library.

Configuration is defined via structs and tags. Values are loaded from files.

Supports TOML by default. Any file format can be used.

Usage

Example

The following example loads configuration files named foo.toml from the /etc/foo/ directory and any .toml files from the /etc/foo.d/ directory. The configuration files are required to have a foo key. The bar key is optional and will have a default value of bardefault if not provided.

import "github.com/Noah-Huppert/goconf"

// Create goconf instance
loader := goconf.NewLoader()

// Define locations to search for configuration files
// Can use shell globs
loader.AddConfigPath("/etc/foo/foo.*")
loader.AddConfigPath("/etc/foo.d/*")

// Load values
type YourConfigStruct struct {
    Foo string `mapstructure:"foo" validate:"required"`
    Bar string `mapstructure:"bar" default:"bardefault"`
}

config := YourConfigStruct{}
err := loader.Load(&config)
panic(err)

Define Configuration

Define configuration parameters in a struct.

Use mapstructure tags to specify the names of fields when being decoded.

Use validate tags to specify value requirements for fields.

Use default tags to specify default field values.

Custom File Formats

The MapDecoder interface allows Goconf to use any file format.

Goconf provides an implementation for TOML files in the github.com/Noah-Huppert/goconf/toml package.

To use any other file format simply implement a MapDecoder and register it with Goconf via the Loader.RegisterFormat() method.

Tests

Run tests:

make test
# Or
make

FAQs

Package last updated on 06 Jan 2020

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