Created
April 1, 2021 14:00
-
-
Save rafi/6a175180dbb6341f768bdbff9c00cf96 to your computer and use it in GitHub Desktop.
Echoserver in Go lang
This file contains 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 ( | |
"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