Skip to content

Instantly share code, notes, and snippets.

@ukautz
Last active May 25, 2020 17:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ukautz/d521d0143dff859f4d67d5ba5b9fe39d to your computer and use it in GitHub Desktop.
Save ukautz/d521d0143dff859f4d67d5ba5b9fe39d to your computer and use it in GitHub Desktop.
Medium > Intro to Go > Full HTTP server
// returns a `200 OK` response with the body `Hello World` to any incoming request
package main
import (
"fmt"
"net/http"
)
func helloWorld(writer http.ResponseWriter, request *http.Request) {
writer.Write([]byte("Hello World"))
}
func main() {
fmt.Println("Starting HTTP server")
http.HandleFunc("/", helloWorld)
err := http.ListenAndServe(":12345", nil)
if err != nil {
panic(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment