This commit is contained in:
2019-10-04 19:49:31 +02:00
parent 2defad24c8
commit 8c5fe54d11
4 changed files with 72 additions and 0 deletions

30
hello-world/helloworld.go Normal file
View File

@@ -0,0 +1,30 @@
package main
import (
"fmt"
"log"
"net/http"
"os"
)
func handler(w http.ResponseWriter, r *http.Request) {
log.Print("Hello world received a request.")
target := os.Getenv("TARGET")
if target == "" {
target = "World"
}
fmt.Fprintf(w, "Hello %s!\n", target)
}
func main() {
log.Print("Hello world sample started.")
http.HandleFunc("/", handler)
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%s", port), nil))
}