Skip to content

Instantly share code, notes, and snippets.

@karl-gustav
Last active September 29, 2023 08:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karl-gustav/7a54487094224eaddb76449e3db6b75a to your computer and use it in GitHub Desktop.
Save karl-gustav/7a54487094224eaddb76449e3db6b75a to your computer and use it in GitHub Desktop.
go webserver
package main
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello world!")
})
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
log.Println("Serving http://localhost:" + port)
log.Fatal(http.ListenAndServe(":"+port, nil))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment