envfile

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2024 License: MIT Imports: 9 Imported by: 0

README

envfile

Package envfile provides functionality to parse files containing environment variables in the format key=value.

Install

go get github.com/kechako/envfile@latest

Usage

package main

import (
	"fmt"
	"log"

	"github.com/kechako/envfile"
)

func main() {
	envs, err := envfile.ParseFile(".env")
	if err != nil {
		log.Fatal(err)
	}

	for key, value := range envs.Envs() {
		fmt.Printf("%s = %v\n", key, value)
	}
}

Documentation

Overview

Package envfile provides functionality to parse files containing environment variables in the format key=value.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Load added in v1.1.0

func Load(r io.Reader) error

Parse reads data from the r, parses the content in the key=value format, and sets environment variables.

func LoadEnvs added in v1.1.0

func LoadEnvs(envs Envs) error

LoadEnvs sets environment variables from envs.

func LoadFile added in v1.1.0

func LoadFile(name string) error

ParseFile reads the named file, parses the content in the key=value format, and sets environment variables.

Types

type Envs

type Envs []string

Envs represents an array of strings, where each string follows the format key=value.

func Parse

func Parse(r io.Reader) (Envs, error)

Parse reads data from the r, parses the content in the key=value format, and returns an Envs type.

func ParseFile

func ParseFile(name string) (Envs, error)

ParseFile reads the named file, parses the content in the key=value format, and returns an Envs type.

func (Envs) Envs

func (envs Envs) Envs() iter.Seq2[string, string]

Envs returns an iterator over key-value pairs from Envs.

func (Envs) Map

func (envs Envs) Map() map[string]string

Map converts Envs array into a map[string]string.

Jump to

Keyboard shortcuts

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