import ( "fmt" "github.com/docker/docker/engine" ) func main() { job := engine.Job{} job.Setenv("GREETING", "Hello") greeting := job.Getenv("GREETING") fmt.Println(greeting) }
Hello
import ( "fmt" "github.com/docker/docker/engine" ) func main() { job := engine.Job{} job.Setenv("GREETING", "Hello") job.Setenv("NAME", "John Doe") greeting := job.Getenv("GREETING") name := job.Getenv("NAME") fmt.Printf("%s, %s!\n", greeting, name) }
Hello, John Doe!In this example, we set two environment variables "GREETING" and "NAME" with values "Hello" and "John Doe" respectively using the "Setenv" method of the job. We then use the "Getenv" method to read the values of these environment variables and print them as a greeting message. In summary, the "Job" struct in the "github.com/docker/docker/engine" package provides the "Getenv" method to read an environment variable value for a given key in the job container's environment. This method can be used to read environment variables set in a job container before or after it has been executed.