in golang/go-cloud-run-hello-world/main.go [22:59]
func main() {
// Initialize template parameters.
service := os.Getenv("K_SERVICE")
if service == "" {
service = "???"
}
revision := os.Getenv("K_REVISION")
if revision == "" {
revision = "???"
}
// Prepare template for execution.
tmpl = template.Must(template.ParseFiles("index.html"))
data = templateData{
Service: service,
Revision: revision,
}
// Define HTTP server.
http.HandleFunc("/", helloRunHandler)
fs := http.FileServer(http.Dir("./assets"))
http.Handle("/assets/", http.StripPrefix("/assets/", fs))
// PORT environment variable is provided by Cloud Run.
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
log.Print("Hello from Cloud Run! The container started successfully and is listening for HTTP requests on $PORT")
log.Printf("Listening on port %s", port)
err := http.ListenAndServe(":"+port, nil)
if err != nil {
log.Fatal(err)
}
}