Skip to content

Commit

Permalink
update attribute format on aws-json protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
kojisaiki committed Dec 27, 2023
1 parent 844a048 commit b013bcf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 20 deletions.
21 changes: 9 additions & 12 deletions app/gosqs/gosqs.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,17 @@ func ListQueues(w http.ResponseWriter, req *http.Request) {
}

type CreateQueueRequest struct {
QueueName string `json: QueueName`
VisibilityTimeout int `json: VisibilityTimeout`
MaximumMessageSize int `json: MaximumMessageSize`
QueueName string `json: QueueName`
Attributes map[string]string `json: Attributes`
Tags map[string]string `json: Tags`
}

type Attributes map[string]string

func parseCreateQueueRequestBody(w http.ResponseWriter, req *http.Request) (bool, CreateQueueRequest, Attributes) {
func parseCreateQueueRequestBody(w http.ResponseWriter, req *http.Request) (bool, CreateQueueRequest) {
requestBody := new(CreateQueueRequest)
attributes := map[string]string{}

// Should remove this flag after validateAndSetQueueAttributes was updated
byJson := false

switch req.Header.Get("Content-Type") {
Expand All @@ -137,21 +137,18 @@ func parseCreateQueueRequestBody(w http.ResponseWriter, req *http.Request) (bool
if err != nil {
panic(err)
}
// TODO: parse from json, and find actual attribute format in aws-json protocol.
attributes["VisibilityTimeout"] = "60"
attributes["MaximumMessageSize"] = "2048"
byJson = true
default:
requestBody.QueueName = req.FormValue("QueueName")
attributes = extractQueueAttributes(req.Form)
requestBody.Attributes = extractQueueAttributes(req.Form)
}

return byJson, *requestBody, attributes
return byJson, *requestBody
}

func CreateQueue(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Content-Type", "application/xml")
byJson, requestBody, attr := parseCreateQueueRequestBody(w, req)
byJson, requestBody := parseCreateQueueRequestBody(w, req)

queueName := requestBody.QueueName

Expand All @@ -177,7 +174,7 @@ func CreateQueue(w http.ResponseWriter, req *http.Request) {
Duplicates: make(map[string]time.Time),
}
if byJson {
if err := validateAndSetQueueAttributesJson(queue, attr); err != nil {
if err := validateAndSetQueueAttributesJson(queue, requestBody.Attributes); err != nil {
createErrorResponse(w, req, err.Error())
return
}
Expand Down
11 changes: 3 additions & 8 deletions app/gosqs/gosqs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,18 +147,13 @@ func TestCreateQueuehandler_POST_CreateQueue(t *testing.T) {
}
}

// type CreateQueueRequest struct {
// QueueName string `json: QueueName`
// VisibilityTimeout int `json: VisibilityTimeout`
// MaximumMessageSize int `json: MaximumMessageSize`
// }

func TestCreateQueuehandler_POST_CreateQueue_aws_json(t *testing.T) {
queueName := "UnitTestQueue1"
requestObj := new(CreateQueueRequest)
requestObj.QueueName = queueName
requestObj.VisibilityTimeout = 60
requestObj.MaximumMessageSize = 2048
requestObj.Attributes = map[string]string{}
requestObj.Attributes["VisibilityTimeout"] = "60"
requestObj.Attributes["MaximumMessageSize"] = "2048"
requestJson, _ := json.Marshal(requestObj)
// Create a request to pass to our handler. We don't have any query parameters for now, so we'll
// pass 'nil' as the third parameter.
Expand Down

0 comments on commit b013bcf

Please sign in to comment.