Skip to content

Instantly share code, notes, and snippets.

@jayco
Created November 27, 2020 01:21
Show Gist options
  • Save jayco/a8396003578eb3a3c837f9992a2c6f01 to your computer and use it in GitHub Desktop.
Save jayco/a8396003578eb3a3c837f9992a2c6f01 to your computer and use it in GitHub Desktop.
echo
package main
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"net/http/httputil"
)
func rootHandler(writer http.ResponseWriter, request *http.Request) {
writer.Header().Set("Access-Control-Allow-Origin", "*")
writer.Header().Set("Access-Control-Allow-Headers", "Content-Range, Content-Disposition, Content-Type, ETag")
writer.WriteHeader(204)
requestDump, _ := httputil.DumpRequest(request, false)
log.Println(string(requestDump))
b, _ := ioutil.ReadAll(request.Body)
var pretty bytes.Buffer
json.Indent(&pretty, b, "", "\t")
log.Println(string(pretty.Bytes()))
}
func main() {
port := 4587
log.Printf("Starting server, listening on port %v \n", port)
http.HandleFunc("/", rootHandler)
http.ListenAndServe(fmt.Sprintf(":%v", port), nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment