-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor for V1 flow supporting AWS Json
- Loading branch information
1 parent
39895d4
commit 7893a9a
Showing
5 changed files
with
148 additions
and
8 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package utils | ||
|
||
import ( | ||
"encoding/json" | ||
"net/http" | ||
|
||
log "github.com/sirupsen/logrus" | ||
|
||
"github.com/gorilla/schema" | ||
) | ||
|
||
var xmlDecoder = schema.NewDecoder() | ||
|
||
// QUESTION - alternately we could have the router.actionHandler method call this, but then our router maps | ||
// need to track the request type AND the function call. I think there'd be a lot of interface switching | ||
// back and forth. | ||
func TransformRequest(resultingStruct interface{}, req *http.Request) (success bool) { | ||
// TODO - put this somewhere else so we don't keep on rehashing this? | ||
xmlDecoder.IgnoreUnknownKeys(true) | ||
// TODO - do I still need the byJSON? | ||
// Should remove this flag after validateAndSetQueueAttributes was updated | ||
//byJson := false | ||
|
||
switch req.Header.Get("Content-Type") { | ||
case "application/x-amz-json-1.0": | ||
//Read body data to parse json | ||
decoder := json.NewDecoder(req.Body) | ||
err := decoder.Decode(resultingStruct) | ||
if err != nil { | ||
log.Debugf("TransformRequest Failure - %s", err.Error()) | ||
return false | ||
} | ||
//byJson = true | ||
default: | ||
// TODO - parse XML | ||
err := req.ParseForm() | ||
if err != nil { | ||
log.Debugf("TransformRequest Failure - %s", err.Error()) | ||
return false | ||
} | ||
err = xmlDecoder.Decode(resultingStruct, req.PostForm) | ||
if err != nil { | ||
log.Debugf("TransformRequest Failure - %s", err.Error()) | ||
return false | ||
} | ||
} | ||
|
||
return true | ||
} |
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
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