env

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 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/fkmatsuda-dev/env

Usage

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

import (
    "github.com/fkmatsuda-dev/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, feel free to send a pull request or create an issue on GitHub. Your feedback is very important for us to improve the project together.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ChkDuration added in v1.1.0

func ChkDuration(name string) (time.Duration, bool, error)

ChkDuration returns the value of the environment variable with the given name as a time.Duration and true if it is set, otherwise it returns 0 and false.

func ChkFloat64 added in v1.1.0

func ChkFloat64(name string) (float64, bool, error)

ChkFloat64 returns the value of the environment variable with the given name as a float64 and true if it is set, otherwise it returns 0.0 and false.

func ChkInt added in v1.1.0

func ChkInt(name string) (int, bool, error)

ChkInt returns the value of the environment variable with the given name as an integer and true if it is set, otherwise it returns 0 and false.

func ChkString added in v1.1.0

func ChkString(name string) (string, bool)

ChkString returns the value of the environment variable with the given name as a string and true if it is set, otherwise it returns empty string and false.

func Duration

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

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, error)

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, error)

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