diff --git a/main.go b/main.go index 6c75b94..a359f45 100644 --- a/main.go +++ b/main.go @@ -4,17 +4,27 @@ import ( "fmt" "net/http" "os" + "strconv" ) func main() { http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { - // method := r.Method - // path := r.URL.Path - responseHeader := r.Header["X-Response-Json"][0] - response := fmt.Sprint(responseHeader) + responseBody := r.Header["X-Response-Json"][0] + var responseCode int + if val, ok := r.Header["X-Response-Code"]; !ok { + responseCode = 200 + } else { + var err error + responseCode, err = strconv.Atoi(val[0]) + if err != nil { + fmt.Println("not a value status code: ", err) + } + } + + w.WriteHeader(responseCode) w.Header().Set("Content-Type", "application/json") - w.Write([]byte(response)) + w.Write([]byte(responseBody)) }) if err := http.ListenAndServe(":8080", nil); err != nil {