kristofbator
This commit is contained in:
30
hello-world-go/helloworld.go
Normal file
30
hello-world-go/helloworld.go
Normal 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))
|
||||
}
|
||||
Reference in New Issue
Block a user