Created
February 21, 2018 18:44
-
-
Save eyeezzi/7d9bb5880a4fc18d9ea4915517a256e9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
func uploadHandler(w http.ResponseWriter, r *http.Request) { | |
var m map[string]interface{} | |
body, err := ioutil.ReadAll(r.Body) | |
if err != nil { | |
http.Error(w, err.Error(), http.StatusInternalServerError) | |
return | |
} | |
// fmt.Println(string(body)) | |
// json.Unmarshal(b, &t) => decode the byte array into a type | |
if err = json.Unmarshal(body, &m); err != nil { | |
http.Error(w, err.Error(), http.StatusInternalServerError) | |
return | |
} | |
// json.Marshal(m) => encode the object m as a byte array containing its json representation. | |
jsonStr, err := json.Marshal(m) | |
if err != nil { | |
http.Error(w, err.Error(), http.StatusInternalServerError) | |
return | |
} | |
fmt.Fprintln(w, string(jsonStr)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment