Skip to main content

API Request Input

In the api package, you define the request and response data structures. You can directly define the parameters to be received as members of the request structure, and they will automatically be converted to the corresponding structure during the request.

For example, modify the previous api request part to:

type ParamReq struct {
g.Meta `path:"/params" method:"post"`
UserName string `p:"name" d:"Lin Chong"`
UserAge int `p:"age" d:"110"`
}

Here, p: or param: is used to specify the request parameter name corresponding to the member, and d: or default: is used to specify the default value. If there are parameters with the same name in both Query and Body, the parameters in the Body take precedence.