genv

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package genv provides operations for environment variables of system.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func All

func All() []string

All returns a copy of strings representing the environment, in the form "key=value".

func Build

func Build(m map[string]string) []string

Build builds a map to an environment variable slice.

func Contains

func Contains(key string) bool

Contains checks whether the environment variable named `key` exists.

func Filter

func Filter(envs []string) []string

Filter filters repeated items from given environment variables.

func Get

func Get(key string, def ...interface{}) *gvar.Var

Get creates and returns a Var with the value of the environment variable named by the `key`. It uses the given `def` if the variable does not exist in the environment.

func GetWithCmd

func GetWithCmd(key string, def ...interface{}) *gvar.Var

GetWithCmd returns the environment value specified `key`. If the environment value does not exist, then it retrieves and returns the value from command line options. It returns the default value `def` if none of them exists.

Fetching Rules: 1. Environment arguments are in uppercase format, eg: GF_<package name>_<variable name>; 2. Command line arguments are in lowercase format, eg: gf.<package name>.<variable name>;

func Map

func Map() map[string]string

Map returns a copy of strings representing the environment as a map.

func MapFromEnv

func MapFromEnv(envs []string) map[string]string

MapFromEnv converts environment variables from slice to map.

func MapToEnv

func MapToEnv(m map[string]string) []string

MapToEnv converts environment variables from map to slice.

func MustRemove

func MustRemove(key ...string)

MustRemove performs as Remove, but it panics if any error occurs.

func MustSet

func MustSet(key, value string)

MustSet performs as Set, but it panics if any error occurs.

func Remove

func Remove(key ...string) (err error)

Remove deletes one or more environment variables.

func Set

func Set(key, value string) (err error)

Set sets the value of the environment variable named by the `key`. It returns an error, if any.

func SetMap

func SetMap(m map[string]string) (err error)

SetMap sets the environment variables using map.

Types

This section is empty.

Jump to

Keyboard shortcuts

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