Skip to content

Instantly share code, notes, and snippets.

@mcastilho
Last active August 30, 2017 20:18
Show Gist options
  • Save mcastilho/b83fac4fde8edd1d39619ff1d550b78a to your computer and use it in GitHub Desktop.
Save mcastilho/b83fac4fde8edd1d39619ff1d550b78a to your computer and use it in GitHub Desktop.
func payloadHandler(w http.ResponseWriter, r *http.Request) {
if r.Method != "POST" {
w.WriteHeader(http.StatusMethodNotAllowed)
return
}
// Read the body into a string for json decoding
var content = &PayloadCollection{}
err := json.NewDecoder(io.LimitReader(r.Body, MaxLength)).Decode(&content)
if err != nil {
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
w.WriteHeader(http.StatusBadRequest)
return
}
// Go through each payload and queue items individually to be posted to S3
for _, payload := range content.Payloads {
go payload.UploadToS3() // <----- DON'T DO THIS
}
w.WriteHeader(http.StatusOK)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment