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.

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

报告相同问题?