Last active
October 29, 2016 09:29
-
-
Save karteek/c766536200f368bd884d776d8431c6c6 to your computer and use it in GitHub Desktop.
Gecho
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
FROM busybox | |
ADD gecho / | |
ENTRYPOINT ["/gecho"] |
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 ( | |
"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