以下都全默認在controller下執行
-
獲取當前請求的referer
fmt.Println(this.Ctx.Request.Referer())
輸出:http://localhost:8080/swagger/ -
獲取當前uri,
fmt.Println(this.Ctx.Request.RequestURI)
輸出: /v1/weather/?longitude=1&latitude=2 -
獲取query參數,形如 /?longitude=1&latitude=2
fmt.Println(this.Ctx.Input.Query("longitude"))
fmt.Println(this.Ctx.Input.Query("latitude"))ps:正常情況下,Query的key不應當以:開頭,以免和Param里的key沖突
-
獲取path參數, 形如http://localhost:8080/userinfo/{uid}這種
fmt.Println(u.GetString(":uid"))
或者this.Ctx.Input.Param(":uid")這里是字符串,如果是其他類型參考
GetString(key string) string
GetStrings(key string) []string
GetInt(key string) (int64, error)
GetBool(key string) (bool, error)
GetFloat(key string) (float64, error) -
直接解析到 struct