You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
docker-whoami/http.go

27 lines
471 B

package main
import (
"os"
"fmt"
"net/http"
"log"
)
func main() {
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
fmt.Fprintf(os.Stdout, "Listening on :%s\n", port)
hostname, _ := os.Hostname()
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(os.Stdout, "I'm %s\n", hostname)
fmt.Fprintf(w, "I'm %s\n", hostname)
})
log.Fatal(http.ListenAndServe(":" + port, nil))
}