<\/span><\/h1>\n\n\n\nos<\/strong> package provides an Environ()<\/strong> function to get the list all environment variables.<\/p>\n\n\n\nGet all the env variables. It returns an array of string.<\/li><\/ul>\n\n\n\nfunc Environ() []string <\/code><\/pre>\n\n\n\nThere is also a way to clear all the env variables. Clearenv()<\/strong> function can be used to achieve the same.<\/p>\n\n\n\nfunc Clearenv()<\/code><\/pre>\n\n\n\n<\/span>Code:<\/strong><\/span><\/h1>\n\n\n\npackage main\n\nimport (\n \"fmt\"\n \"log\"\n \"os\"\n)\n\nfunc main() {\n \/\/Set env a to b\n err := os.Setenv(\"a\", \"b\")\n if err != nil {\n log.Fatal(err)\n }\n\n err = os.Setenv(\"c\", \"d\")\n if err != nil {\n log.Fatal(err)\n }\n\n \/\/Get all env variables\n fmt.Println(os.Environ())\n\n \/\/Clear all env variables\n os.Clearenv()\n\n \/\/Again get all env variable\n fmt.Println(os.Environ())\n}<\/code><\/pre>\n\n\n\nOutput:<\/strong><\/p>\n\n\n\nList of all env varialbes on your system including a and b<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"Table of Contents OverviewCode: Overview os package provides an Environ() function to get the list all environment variables. Get all the env variables. It returns an array of string. There is also…<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","footnotes":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false},"categories":[1],"tags":[],"class_list":["post-1428","post","type-post","status-publish","format-standard","hentry","category-tech"],"yoast_head":"\n
List all env variables in Go - Welcome To Golang By Example<\/title>\n \n \n \n \n \n \n \n \n \n \n \n \n \n\t \n\t \n\t \n