Пример #1
0
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)
}
Пример #2
0
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)
}
Пример #3
0
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)

}
Пример #4
0
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)
}
Пример #5
0
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)
}
Пример #6
0
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)
}
Пример #7
0
func greetLocal() {
	defer un(trace("greetLocal"))
	greet, _ := helloworld.Greet("English")
	fmt.Printf("Here we say: %v\n", greet)
}
Пример #8
0
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)
}