Created
January 14, 2020 13:54
-
-
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]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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