Reading & Setting environment variables in Go

📅️ Published: June 9, 2020  • 🕣 1 min read

Use os.Getenv() and os.Setenv() for reading and setting environment variables.


package main

import (

func main() {
	os.Setenv("NAME", "gopher")

	fmt.Printf("My Desktop Environment : %s.\n", os.Getenv("XDG_CURRENT_DESKTOP"))
Written by Human, Not by AI

Tired of fucking up with git everyday?

ugit helps you undo git commands with ease. Undo from 20+ git scenarios

ugit cli demo screen