Skip to content

Instantly share code, notes, and snippets.

@Ebazhanov
Forked from monkrus/Go simple webserver
Created April 21, 2020 22:08
Show Gist options
  • Save Ebazhanov/8ddd295a60bf4db6ac47a4e21376e096 to your computer and use it in GitHub Desktop.
Save Ebazhanov/8ddd295a60bf4db6ac47a4e21376e096 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