func main()

in golang/go-guestbook/src/frontend/main.go [28:60]


func main() {
	// GUESTBOOK_API_ADDR environment variable is provided in guestbook-frontend.deployment.yaml.
	backendAddr := os.Getenv("GUESTBOOK_API_ADDR")
	if backendAddr == "" {
		log.Fatal("GUESTBOOK_API_ADDR environment variable not specified")
	}

	// PORT environment variable is provided in guestbook-frontend.deployment.yaml.
	port := os.Getenv("PORT")
	if port == "" {
		log.Fatal("PORT environment variable not specified")
	}

	// Parse html templates and save them to global variable.
	t, err := template.New("").Funcs(map[string]interface{}{
		"since": sinceDate,
	}).ParseGlob("templates/*.tpl")
	if err != nil {
		log.Fatalf("could not parse templates: %+v", err)
	}
	tpl = t

	// Register http handlers and start listening on port.
	fe := &frontendServer{backendAddr: backendAddr}
	fs := http.FileServer(http.Dir("static"))
	http.Handle("/static/", http.StripPrefix("/static/", fs))
	http.HandleFunc("/", fe.homeHandler)
	http.HandleFunc("/post", fe.postHandler)
	log.Printf("frontend server listening on port %s", port)
	if err := http.ListenAndServe(":"+port, nil); err != nil {
		log.Fatalf("server listen error: %+v", err)
	}
}