Standard library / os

os.Clearenv()

Removes all environment variables from this process, not its parent. Avoid in shared application code; this standalone fixture is isolated. Example intended for Linux/AMD64 with Go 1.23.2 in a disposable working directory; other platforms may differ. Expected stdout: '0\n'.

Formal Syntax & Structure

go syntaxgo
func Clearenv()

Working Example

Example Snippetgo
package main
import (  "fmt"  "os")
func must(e error) {  if e != nil {    panic(e)  }}func main() { os.Clearenv(); fmt.Println(len(os.Environ())) }
Go Reference