Move Cloud Run image property to GCP config struct
Signed-off-by: Tihomir Jovicic <tihomir.jovicic.develop@gmail.com>
This commit is contained in:
35
examples/cloudrun-app/go-http-server/main.go
Normal file
35
examples/cloudrun-app/go-http-server/main.go
Normal file
@@ -0,0 +1,35 @@
|
||||
// Sample run-helloworld is a minimal Cloud Run service.
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
log.Print("starting server...")
|
||||
http.HandleFunc("/", handler)
|
||||
|
||||
// Determine port for HTTP service.
|
||||
port := os.Getenv("PORT")
|
||||
if port == "" {
|
||||
port = "8080"
|
||||
log.Printf("defaulting to port %s", port)
|
||||
}
|
||||
|
||||
// Start HTTP server.
|
||||
log.Printf("listening on port %s", port)
|
||||
if err := http.ListenAndServe(":"+port, nil); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func handler(w http.ResponseWriter, r *http.Request) {
|
||||
name := os.Getenv("NAME")
|
||||
if name == "" {
|
||||
name = "World"
|
||||
}
|
||||
fmt.Fprintf(w, "Hello %s!\n", name)
|
||||
}
|
Reference in New Issue
Block a user