env

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2023 License: MIT Imports: 3 Imported by: 1

README

env

The env project is a library written in Go that provides functions to read values from environment variables. The library supports the following variable types:

  • Int
  • Duration
  • Float64
  • String

All functions have two parameters:

  • The first parameter is the name of the environment variable to be read.
  • The second parameter is the default value to be returned if the variable cannot be read.
  • The return type of the function will match the type of the default value provided.

Installation

You can install the env library using the following command:

go get github.com/yourusername/env

Usage

To use the env library, import the relevant function for the type of environment variable you wish to read.

import (
    "github.com/yourusername/env"
)

// Reading an integer environment variable
myInt := env.ReadInt("MY_INT_VAR", 10)

// Reading a duration environment variable
myDuration := env.ReadDuration("MY_DURATION_VAR", time.Second * 60)

// Reading a float environment variable
myFloat := env.ReadFloat64("MY_FLOAT_VAR", 3.14)

// Reading a string environment variable
myString := env.ReadString("MY_STRING_VAR", "default_value")

If the environment variable cannot be read, the function will return the default value provided.

License

This project is licensed under the MIT License. See the LICENSE file for more information.

Contributing

If you would like to contribute to the env library, please submit a pull request on the GitHub repository.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Duration

func Duration(name string, defaultValue time.Duration) time.Duration

Duration returns the value of the environment variable with the given name as a time.Duration. If the environment variable is not set or cannot be parsed as a time.Duration, the default value is returned.

func Float64

func Float64(name string, defaultValue float64) float64

Float64 returns the value of the environment variable with the given name as a float64. If the environment variable is not set or cannot be parsed as a float64, the default value is returned.

func Int

func Int(name string, defaultValue int) int

Int returns the value of the environment variable with the given name as an integer. If the environment variable is not set or cannot be parsed as an integer, the default value is returned.

func String

func String(name string, defaultValue string) string

String returns the value of the environment variable with the given name as a string. If the environment variable is not set, the default value is returned.

Types

This section is empty.

Jump to

Keyboard shortcuts

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