Documentation ¶
Overview ¶
Gonv package is a library to manipulate environmental variables in golang.
read more in Readme.md file
Example (ManageEnvironmentalVariables) ¶
package main import ( "fmt" "github.com/jenazads/gonv" ) func main() { // using system environmental variables gonv.SetEnv("BOOL", true) isBool, _ := gonv.GetBoolEnv("BOOL") username, _ := gonv.GetEnv("USER") // return $USER system variable fmt.Println(username, ", ", isBool) gonv.SetEnv("NAME", "Jenazads") nameSystem, _ := gonv.GetEnv("NAME") fmt.Println("name:", nameSystem) gonv.UpdateEnv("NAME", 4) nameUpdatedsystem, _ := gonv.GetIntEnv("NAME") fmt.Println("name updated:", nameUpdatedsystem) // using object environmental variables gonvObject := gonv.NewGonv() gonvObject.SetEnv("BOOL", true) isBool, _ = gonvObject.GetBoolEnv("BOOL") usernameObj, _ := gonvObject.GetEnv("USER") // return nil fmt.Println(usernameObj, ", ", isBool) gonvObject.SetEnv("NAME", "Jenazads") nameLocal, _ := gonvObject.GetEnv("NAME") fmt.Println("name:", nameLocal) fmt.Println(gonvObject) gonvObject.UpdateEnv("NAME", 4) nameLocal, _ = gonv.GetIntEnv("NAME") // we can set another type because is interface type ! fmt.Println("name updated:", nameLocal) fmt.Println(gonvObject) }
Output:
Index ¶
- Variables
- func GetBoolEnv(tag string) (bool, error)
- func GetEnv(tag string) (string, error)
- func GetIntEnv(tag string) (int, error)
- func GetStringEnv(tag string) (string, error)
- func SetEnv(tag string, value interface{}) error
- func UpdateEnv(tag string, value interface{}) error
- type Gonv
- func (gnv *Gonv) GetBoolEnv(tag string) (bool, error)
- func (gnv *Gonv) GetEnv(tag string) (interface{}, error)
- func (gnv *Gonv) GetIntEnv(tag string) (int, error)
- func (gnv *Gonv) GetStringEnv(tag string) (string, error)
- func (gnv *Gonv) SetEnv(tag string, value interface{}) error
- func (gnv *Gonv) UpdateEnv(tag string, value interface{}) error
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( GonvErrNotFound = errors.New("Environmental Variable not found.\n") GonvErrAlreadyExist = errors.New("Environmental Variable is already exist.\n") )
list of errors
Functions ¶
func GetBoolEnv ¶
Get environmental variable and transforms to bool
func GetStringEnv ¶
Get environmental variable and transforms to string
Types ¶
type Gonv ¶
type Gonv struct {
// contains filtered or unexported fields
}
Gonv object
func (*Gonv) GetBoolEnv ¶
Get environmental variable and transforms to bool
func (*Gonv) GetStringEnv ¶
Get environmental variable and transforms to string
Click to show internal directories.
Click to hide internal directories.