envmap

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2025 License: MIT Imports: 6 Imported by: 0

README

envmap

go get github.com/artarts36/envmap

This library converts environment configuration structure to map[string]string.

envmap does the reverse of caarlos0/env, which converts environment variables into a Go structure.

Supported tags

  • env
  • envPrefix
  • envSeparator
  • envKeyValSeparator

Usage example:

package main

import (
	"fmt"
	"time"

	"github.com/artarts36/envmap"
)

type Config struct {
	Mode string        `env:"MODE"`
	Timeout time.Duration `env:"TIMEOUT"`
}

func main() {
	result, _ := envmap.Convert(Config{
		Mode: "prod",
		Timeout: 30 * time.Second,
	}, envmap.WithPrefix("APP_"))

	fmt.Println(result)
	// map[string]string
	// APP_MODE: prod
	// APP_TIMEOUT: 30s
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Convert

func Convert(v interface{}, opt ...Opt) (map[string]string, error)

func MustConvert

func MustConvert(v interface{}, opt ...Opt) map[string]string

Types

type Opt

type Opt func(o *config)

func WithPrefix

func WithPrefix(prefix string) Opt

Jump to

Keyboard shortcuts

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