-
-
Save chsjiang/ea9ae04c0f5270ebf01a01cdb3e772d0 to your computer and use it in GitHub Desktop.
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
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 { | |
// let's create a job with the payload | |
work := Job{Payload: payload} | |
// Push the work onto the queue. | |
JobQueue <- work | |
} | |
w.WriteHeader(http.StatusOK) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment