host string flag.IntVar(&port, "port", 8080, "port number") flag.StringVar(&host, "host", "localhost", "hostname") flag.VisitAll(func(f *flag.Flag) { if s := os.Getenv(strings.ToUpper(f.Name)); s != "" { f.Value.Set(s) } }) flag.Parse() fmt.Printf("%s:%d\n", host, port) } 1 https://mattn.kaoriya.net/software/lang/go/20170609110526.htm