Socket
Book a DemoInstallSign in
Socket

github.com/andreiavrammsd/config

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/andreiavrammsd/config

Source
Go
Version
v0.7.0
Version published
Created
Source

Config

codecov GoDoc

Package config loads configuration values into given struct.

Requirements for configuration struct:

  • A non-nil pointer to the struct must be passed.
  • Fields must be exported. Unexported fields will be ignored.
  • A field can have the env tag which defines the key of the value. If no tag provided, the key will be the uppercase full path of the field (all the fields names starting root until current field, joined by underscore).
  • The json tag will be used for loading from JSON.

Input sources:

  • environment variables
  • environment variables from files
  • byte array
  • json
package main

import (
	"fmt"
	"log"

	"github.com/andreiavrammsd/config"
)

type Config struct {
	Username string `env:"CUSTOM_USERNAME_TAG"`
	Tag      string `default:"none"`
}

func main() {
	input := []byte(`CUSTOM_USERNAME_TAG=msd # username`)

	cfg := Config{}
	if err := config.New().FromBytes(&cfg, input); err != nil {
		log.Fatalf("cannot load config: %s", err)
	}

	fmt.Println(cfg.Username)
	fmt.Println(cfg.Tag)
}

Install

go get github.com/andreiavrammsd/config

Usage

See examples and tests.

Testing and QA tools for development

See Makefile and VS Code setup.

FAQs

Package last updated on 30 Apr 2025

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