小编tra*_*tor的帖子

如何从Go上的请求主体获取JSON

我是Go的新手,但到目前为止,我非常喜欢它。

我有一个我不知道的问题。我正在将API从Node迁移到Go,并且有此日志必须捕获POST 原样并将其保存到jsonbPostgresql数据库的type列中。

这意味着我不能使用struct或预定的任何东西。

POST是使用原始身体制作的,Content-Type: application/json如下所示:

{
    "debug": false,
    "order_id_gea": 326064,
    "increment_id_gea": 200436102,
    "date": "2017-05-18T01:44:44+00:00",
    "total_amount": 10000.00,
    "currency": "MXN",
    "payment_method": "Referencia bancaria",
    "reference": "857374",
    "buyer": {
        "buyer_id_gea": 1234,
        "full_name": "Juan Perez Martinez",
        "email": "juanperez@gmail.com",
        "phone": "5512341234"
    },
    "products": [
        {
            "sku":"PEP16114",
            "price": 10000.00,
            "currency": "MXN",
            "student": {
                "school_id_gea": 172,
                "grade_id_gea": 119,
                "level_id_gea": 36,
                "name": "Benancio",
                "last_name": "Perez",
                "second_last_name": "Garcia",
                "email": "benancio@gmail.com"
            }
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

在Node + Hapi上非常简单:

const payload = request.payload
Run Code Online (Sandbox Code Playgroud)

然后我可以从访问JSON …

json http http-post httprequest go

3
推荐指数
1
解决办法
9769
查看次数

标签 统计

go ×1

http ×1

http-post ×1

httprequest ×1

json ×1