Skip to content

Instantly share code, notes, and snippets.

@monkrus
Created April 17, 2020 03:27
Show Gist options
  • Save monkrus/cfb9f29fa0d36cb907a59a9ed25562bf to your computer and use it in GitHub Desktop.
Save monkrus/cfb9f29fa0d36cb907a59a9ed25562bf to your computer and use it in GitHub Desktop.
Write web server in 5 lines of code
package main
import (
"log"
"net/http"
)
func main() {
//root path handles EVERY request received
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
//input/outputs work with slices of bytes
w.Write([]byte("sos"))
})
err := http.ListenAndServe(":3000", nil)
if err != nil {
log.Fatal(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment