dongxing2263 2015-10-12 00:06
浏览 13

RESTFUL API中的golang结构或地图

When creating a webserver in golang, is there any specific reason why JSON data would be represented as a MAP over a STRUCT or vice versa? ..or is this decision based purely on user preference ?

  • 写回答

1条回答 默认 最新

  • duandou8457 2015-10-12 00:22

    I think this discussion could go either way but the advantages of using structs vs maps are that structs give you an idea of how the schema should look like whereas a map leaves the schema open-ended.

    If you use structs, developers who look at the code will have a clear idea of what parameters you're expecting for the API or how the response of the API may look like without digging further into implementation detail. On the other hand if the requests or responses were maps, they would have to look at the implementation detail to see what keys and values are being assigned. Hope this helps!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?



  • ¥30 电脑误删了手机的照片怎么恢复?
  • ¥15 (标签-python|关键词-char)
  • ¥15 python+selenium,在新增时弹出了一个输入框
  • ¥15 苹果验机结果的api接口哪里有??单次调用1毛钱及以下。
  • ¥20 学生成绩管理系统设计
  • ¥15 来一个cc穿盾脚本开发者
  • ¥15 CST2023安装报错
  • ¥15 使用diffusionbert生成文字 结果是PAD和UNK怎么办
  • ¥15 有人懂怎么做大模型的客服系统吗?卡住了卡住了
  • ¥20 firefly-rk3399上启动卡住了