2019-07-17 07:37
浏览 87

什么等于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]")

图片转代码服务由CSDN问答提供 功能建议

我正在尝试使用gin框架在golang中实现数据表服务器端处理。 我在php中有我的资源。 我想将其转换为golang杜松子酒。 需要一点帮助。

  // php代码
 $ params = $ _REQUEST; 
 $ draw = $ params [“ 画“]; 
 $ orderColumn = $ params ['order'] [0] ['column']; 
 $ sortColumnDir = $ params ['order'] [0] ['dir']; 
 <代码> // golang杜松子酒代码
 //不知道如何获取$ _REQUEST,如php 
 /  / $ params = $ _REQUEST;  //这里是gin中的go代码?
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.

    解决 无用
    打赏 举报

相关推荐 更多相似问题