Skip to content

Instantly share code, notes, and snippets.

@rafi
Created April 1, 2021 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rafi/6a175180dbb6341f768bdbff9c00cf96 to your computer and use it in GitHub Desktop.
Save rafi/6a175180dbb6341f768bdbff9c00cf96 to your computer and use it in GitHub Desktop.
Echoserver in Go lang
package main
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)
func main() {
http.ListenAndServe(":5001", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
b, err := ioutil.ReadAll(r.Body)
if err != nil {
panic(err)
}
defer r.Body.Close()
var buf bytes.Buffer
if err := json.Indent(&buf, b, " >", " "); err != nil {
panic(err)
}
fmt.Println(buf.String())
}))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment