Categorygithub.com/lpernett/godotenv
modulepackage
0.0.0-20230527005122-0de1d4c5ef5e
Repository: https://github.com/lpernett/godotenv.git
Documentation: pkg.go.dev

# README

Installation

As a library

go get github.com/lpernett/godotenv

or if you want to use it as a bin command

go >= 1.17

go install github.com/lpernett/godotenv/cmd/godotenv@latest

go < 1.17

go get github.com/lpernett/godotenv/cmd/godotenv

Usage

Add your application configuration to your .env file in the root of your project:

S3_BUCKET=YOURS3BUCKET
SECRET_KEY=YOURSECRETKEYGOESHERE

Then in your Go app you can do something like

package main

import (
    "log"
    "os"

    "github.com/lpernett/godotenv"
)

func main() {
  err := godotenv.Load()
  if err != nil {
    log.Fatal("Error loading .env file")
  }

  s3Bucket := os.Getenv("S3_BUCKET")
  secretKey := os.Getenv("SECRET_KEY")

  // now do something with s3 or whatever
}

# Packages

No description provided by the author
No description provided by the author

# Functions

Exec loads env vars from the specified filenames (empty map falls back to default) then executes the cmd specified.
Load will read your env file(s) and load them into ENV for this process.
Marshal outputs the given environment as a dotenv-formatted environment file.
Overload will read your env file(s) and load them into ENV for this process.
Parse reads an env file from io.Reader, returning a map of keys and values.
Read all env (with same file loading semantics as Load) but return values as a map rather than automatically writing values into env.
Unmarshal reads an env file from a string, returning a map of keys and values.
Write serializes the given environment and writes it to a file.