Created
July 9, 2020 12:59
-
-
Save martin-g/5a857be4a0767794757218f5ef987155 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
// run with: env PORT=8081 go run http-server.go | |
import ( | |
"fmt" | |
"log" | |
"net/http" | |
"os" | |
) | |
func main() { | |
port := os.Getenv("PORT") | |
if port == "" { | |
log.Fatal("Please specify the HTTP port as environment variable, e.g. env PORT=8081 go run http-server.go") | |
} | |
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request){ | |
fmt.Fprintf(w, "Hello World") | |
}) | |
log.Fatal(http.ListenAndServe(":" + port, nil)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment