dongrang2140 2019-07-17 07:37
浏览 113
已采纳

什么等于golang中的PHP $ _REQUEST?

I am trying to implement datatables server-side-processing in golang with gin framework. I have my resource in php. I want to convert it into golang gin. Need a little help.

// php codes
$params = $_REQUEST;
$draw = $params["draw"];
$orderColumn = $params['order'][0]['column'];
$sortColumnDir = $params['order'][0]['dir'];
// golang gin codes
// no idea what to do to get $_REQUEST as in php
// $params = $_REQUEST; // here what will be go code in gin ?
// I have tried following, but not sure
draw := c.Request.Form.Get("draw")
orderColumn := c.Request.Form.Get("order[0][column]")
sortColumnDir := c.Request.Form.Get("order[0][dir]")
  • 写回答

1条回答 默认 最新

  • duandgfh0506 2019-07-17 08:46
    关注
    1. Stop thinking about $_REQUEST. Simply forget it exists. There is luckily no such thing in Go (for various reasons), and will never be.

    2. Read the docs; figure out that c.Request is actually a http.Request.

    3. Read its docs, figure out its Form field is an url.Values.

    4. Read its docs, figure out it's a map of keys which are names of query parameters to slices of the arguments of these parameters.

    5. Armed with that knowledge, in your request processing code, dump the whole contents of the c.Request.Form somewhere (that depends on how you run your server — if you fire it off right in a terminal for testing, then a simple log.Print(c.Request.Form) will suffice).

      Study what's there.

    6. Work from there.

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

报告相同问题?

悬赏问题

  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题