xonfig

package module
v2.0.0-...-78c7449 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 15, 2023 License: MIT Imports: 4 Imported by: 0

README

xonfig-go v2

Load configuration from either CONFIG environment variable or config.toml. Simple, strict.

Import

import "github.com/nixberg/xonfig-go/v2"

Example

package main

import (
	"github.com/gin-gonic/gin"
	"github.com/nixberg/xonfig-go/v2"
)

func main() {
	config := xonfig.MustLoad[struct {
		GinMode         string
		ListenAddress   string
		TrustedPlatform string

		Accounts gin.Accounts
	}]()

	...
}

Contents of ./config.toml:

GinMode = "debug"
ListenAddress = "localhost:8080"
TrustedPlatform = ""

Accounts = {}

Contents of CONFIG environment variable:

GinMode = "release"
ListenAddress = "0.0.0.0:8080"
TrustedPlatform = "CF-Connecting-IP"

[Accounts]
admin = "8mwf9mrtbu2z2zhbec7qg6kc63"

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MustLoad

func MustLoad[Config any]() (config Config)

func MustLoadOr

func MustLoadOr[Config any](config Config) Config

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL