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]")
Stop thinking about $_REQUEST
. Simply forget it exists. There is luckily no such thing in Go (for various reasons), and will never be.
Read the docs; figure out that c.Request
is actually a http.Request
.
Read its docs, figure out its Form
field is an url.Values
.
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.
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.
Work from there.