-1

In order to send this JSON with Iris Go

{
  "response_type": "in_channel",
  "text": "It's 80 degrees right now.",
  "attachments": [
    {
        "text":"Partly cloudy today and tomorrow"
    }
  ]
}

I'm trying with this but is not working

ctx.JSON(iris.Map{
    "text": "It's 80 degrees right now.",
    "response_type": "in_channel",
    "attachments":[{ "text": "Partly cloudy today and tomorrow" }],
})

Because the following error appear in the attachments line

syntax error: unexpected {, expecting expression

Do you know how to fix it?

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
SoldierCorp
  • 7,610
  • 16
  • 60
  • 100
  • 1
    a little bit of context around iris: https://github.com/julienschmidt/httprouter/issues/160 and http://www.florinpatan.ro/2016/10/why-you-should-not-use-iris-for-your-go.html – Yandry Pozo Jan 23 '18 at 06:50

1 Answers1

1

In your Go code, you don't specify a type for the array or its element. Assuming you want it to be iris.Map:

ctx.JSON(iris.Map{
    "text": "It's 80 degrees right now.",
    "response_type": "in_channel",
    "attachments": []iris.Map{iris.Map{ "text": "Partly cloudy today and tomorrow" }},
})
Adrian
  • 42,911
  • 6
  • 107
  • 99
  • @SoldierCorp note that you can omit the 3rd `iris.Map` from the provided example to reduce stutter as is explained [here](https://golang.org/ref/spec#Composite_literals). Mainly this part: *"Within a composite literal of array, slice, or map type T, elements or map keys that are themselves composite literals may elide the respective literal type if it is identical to the element or key type of T."* – mkopriva Jan 22 '18 at 17:42
  • @mkopriva Didn't know that, I will check that article. Thanks! – SoldierCorp Jan 22 '18 at 18:19