func main() { lang := flag.String("lang", "English", "a language in which to get greeting.") flag.Parse() greet, err := helloworld.Greet(*lang) if err != nil { log.Fatal(err) } fmt.Printf("%s\n", greet) }
func HandleGet(w http.ResponseWriter, r *http.Request) { lang := r.FormValue("language") greet, err := helloworld.Greet(lang) if err != nil { handleError(w, err) return } sendJSON(w, greet) }
func main() { lang := flag.String("lang", "English", "a language in which to get greeting.") flag.Parse() greet, err := helloworld.Greet(*lang) if err != nil { if strings.Contains(err.Error(), helloworld.ErrorNotFound) { listLanguages() } else { log.Fatal(err) } } fmt.Printf("%s\n", greet) }
func greetChina() { defer un(trace("greetChina")) time.Sleep(time.Millisecond * 5901) greet, _ := helloworld.Greet("Chinese") fmt.Printf("In China (5901 miles away) they say: %v\n", greet) }
func greetFrance() { defer un(trace("greetFrance")) time.Sleep(time.Millisecond * 5560) greet, _ := helloworld.Greet("French") fmt.Printf("In France (5560 miles away) they say: %v\n", greet) }
func greetMexico() { defer un(trace("greetMexico")) time.Sleep(time.Millisecond * 1877) greet, _ := helloworld.Greet("Spanish") fmt.Printf("In Mexico City (1877 miles away), they say: %v\n", greet) }
func greetLocal() { defer un(trace("greetLocal")) greet, _ := helloworld.Greet("English") fmt.Printf("Here we say: %v\n", greet) }
func greet(d Destination) { time.Sleep(time.Duration(d.Distance) * time.Millisecond) greet, _ := helloworld.Greet(d.Language) fmt.Printf("In %s (%d miles away), they say: %s\n", d.Name, d.Distance, greet) }