Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
simple http server, just print request path and echo post payload
package main
import (
func sayHello(w http.ResponseWriter, r *http.Request) {
path := getPath(r.URL.Path)
fmt.Println("enter: ", path)
c, err := ioutil.ReadAll(r.Body)
if err != nil {
errMsg := fmt.Sprintf("error: %v", err)
func getPath(w string) string {
return strings.TrimPrefix(w, "/")
func main() {
http.HandleFunc("/", sayHello)
if err := http.ListenAndServe(":8080", nil); err != nil {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment