// Homework 47, problem 2: Settings from the environment. // // Give this program two settings, each with a flag, an environment variable // and a default. A flag beats the environment variable, which beats the // default: // -name GREET_NAME default "friend" // -times GREET_TIMES default 1, must be from 1 to 10 // A GREET_TIMES that is not a whole number, or a -times outside 1 to 10, is an // error: print it to stderr and exit with code 1. // // Run with: go run exercises/47/homework/02-greeter-config.go // or: go run exercises/47/homework/02-greeter-config.go -name Keiko -times 3 package main import "fmt" type config struct { name string times int } // TODO: write loadConfig() (config, error) here. func main() { // TODO: call loadConfig in place of this line. cfg := config{name: "friend", times: 1} for range cfg.times { fmt.Printf("Hello, %s!\n", cfg.name) } }