Create a gist now

Instantly share code, notes, and snippets.

@karteek /Dockerfile
Last active Oct 29, 2016

What would you like to do?
Gecho
FROM busybox
ADD gecho /
ENTRYPOINT ["/gecho"]
package main
import (
"fmt"
"io/ioutil"
"net/http"
)
func handler(w http.ResponseWriter, r *http.Request) {
fmt.Printf("-- Request Start --\n")
fmt.Printf("%s %s\n", r.Method, r.RequestURI)
for k := range r.Header {
fmt.Printf("%s: %s\n", k, r.Header[k])
}
if r.ContentLength > 0 {
body, err := ioutil.ReadAll(r.Body)
if err != nil {
fmt.Printf("Error reading body\n")
} else {
fmt.Printf("%s\n", body)
}
}
w.Header().Set("Server", "Gecho Server")
w.WriteHeader(200)
fmt.Printf("-- Request End --\n\n")
}
func main() {
http.HandleFunc("/", handler)
http.ListenAndServe(":8080", nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment