1

In the Golang Revel web framework, what's the difference between setting function arguments as parameters (for both GET and POST)

func (c Machine) TestConnection(addr string, port int, username, password string) revel.Result

versus retrieving HTTP parameters from within the function

addr := c.Params.Get("addr")
port, _ := strconv.Atoi(c.Params.Get("port"))
username := c.Params.Get("username")
password := c.Params.Get("password")

Also, if I use the function arguments method (the first method), can I still validate the HTTP parameters with c.Validation.Required("addr").Ok?

4

1 回答 1

1

你可以使用任何你喜欢的。但是,将它们定义为方法参数可以让框架负责将请求中的字符串解析为您需要的类型。所以它是为了方便而提供的。

于 2017-09-07T09:03:22.930 回答