Standard library / os

os.Environ()

Returns a copy of the current environment as key=value entries. Do not log the full environment because it can contain secrets. Example intended for Linux/AMD64 with Go 1.23.2 in a disposable working directory; other platforms may differ. Expected stdout: 'true\n'.

Formal Syntax & Structure

go syntaxgo
func Environ() []string

Return Value

[]string

Returns a copy of the current environment as key=value entries.

Working Example

Example Snippetgo
package main
import (  "fmt"  "os"  "slices")
func must(e error) {  if e != nil {    panic(e)  }}func main() {  must(os.Setenv("BYTEMIND_SAMPLE", "hello"))  fmt.Println(slices.Contains(os.Environ(), "BYTEMIND_SAMPLE=hello"))}
Go Reference