Skip to content

Instantly share code, notes, and snippets.

@mtilson
Created January 14, 2020 13:54
Show Gist options
  • Save mtilson/233be0bd809af030107e12892b446c1c to your computer and use it in GitHub Desktop.
Save mtilson/233be0bd809af030107e12892b446c1c to your computer and use it in GitHub Desktop.
how to create pure++ http server (with own router and logging) - in less than 20 code lines [golang] [20lines]
package main
import (
"log"
"net/http"
)
func handler(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("ok"))
}
func main() {
mux := http.NewServeMux()
mux.HandleFunc("/", handler)
if err := http.ListenAndServe(":8765", mux); err != nil {
log.Fatalf("error at starting server: %s", err.Error())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment