gonv

package module
v0.0.0-...-e69b167 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2019 License: MIT Imports: 3 Imported by: 0

README

Golang + Environment = gonv

gonv (Golang eNVironment) is a Golang implementation to manage environment variables in operating system.
You can see an extended doc in godocs.

Install it writing in terminal:

go get github.com/fmorenovr/gonv

Example:

  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)
  }

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

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

func GetBoolEnv(tag string) (bool, error)

Get environmental variable and transforms to bool

func GetEnv

func GetEnv(tag string) (string, error)

Get environmental variable

func GetIntEnv

func GetIntEnv(tag string) (int, error)

Get environmental variable and transforms to int

func GetStringEnv

func GetStringEnv(tag string) (string, error)

Get environmental variable and transforms to string

func SetEnv

func SetEnv(tag string, value interface{}) error

Set new environmental variable

func UpdateEnv

func UpdateEnv(tag string, value interface{}) error

Update environmental variable

Types

type Gonv

type Gonv struct {
	// contains filtered or unexported fields
}

Gonv object

func NewGonv

func NewGonv() *Gonv

Create New Gonv Object

func (*Gonv) GetBoolEnv

func (gnv *Gonv) GetBoolEnv(tag string) (bool, error)

Get environmental variable and transforms to bool

func (*Gonv) GetEnv

func (gnv *Gonv) GetEnv(tag string) (interface{}, error)

Get environmental variable

func (*Gonv) GetIntEnv

func (gnv *Gonv) GetIntEnv(tag string) (int, error)

Get environmental variable and transforms to int

func (*Gonv) GetStringEnv

func (gnv *Gonv) GetStringEnv(tag string) (string, error)

Get environmental variable and transforms to string

func (*Gonv) SetEnv

func (gnv *Gonv) SetEnv(tag string, value interface{}) error

Set new environmental variable

func (*Gonv) UpdateEnv

func (gnv *Gonv) UpdateEnv(tag string, value interface{}) error

Update environmental variable

Jump to

Keyboard shortcuts

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