github.com/gogf/gf@v1.16.9/net/ghttp/internal/client/client_var.go (about) 1 // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 // 3 // This Source Code Form is subject to the terms of the MIT License. 4 // If a copy of the MIT was not distributed with this file, 5 // You can obtain one at https://github.com/gogf/gf. 6 7 package client 8 9 import ( 10 "github.com/gogf/gf/container/gvar" 11 ) 12 13 // GetVar sends a GET request, retrieves and converts the result content to specified pointer. 14 // The parameter <pointer> can be type of: struct/*struct/**struct/[]struct/[]*struct/*[]struct, etc. 15 func (c *Client) GetVar(url string, data ...interface{}) *gvar.Var { 16 return c.RequestVar("GET", url, data...) 17 } 18 19 // PutVar sends a PUT request, retrieves and converts the result content to specified pointer. 20 // The parameter <pointer> can be type of: struct/*struct/**struct/[]struct/[]*struct/*[]struct, etc. 21 func (c *Client) PutVar(url string, data ...interface{}) *gvar.Var { 22 return c.RequestVar("PUT", url, data...) 23 } 24 25 // PostVar sends a POST request, retrieves and converts the result content to specified pointer. 26 // The parameter <pointer> can be type of: struct/*struct/**struct/[]struct/[]*struct/*[]struct, etc. 27 func (c *Client) PostVar(url string, data ...interface{}) *gvar.Var { 28 return c.RequestVar("POST", url, data...) 29 } 30 31 // DeleteVar sends a DELETE request, retrieves and converts the result content to specified pointer. 32 // The parameter <pointer> can be type of: struct/*struct/**struct/[]struct/[]*struct/*[]struct, etc. 33 func (c *Client) DeleteVar(url string, data ...interface{}) *gvar.Var { 34 return c.RequestVar("DELETE", url, data...) 35 } 36 37 // HeadVar sends a HEAD request, retrieves and converts the result content to specified pointer. 38 // The parameter <pointer> can be type of: struct/*struct/**struct/[]struct/[]*struct/*[]struct, etc. 39 func (c *Client) HeadVar(url string, data ...interface{}) *gvar.Var { 40 return c.RequestVar("HEAD", url, data...) 41 } 42 43 // PatchVar sends a PATCH request, retrieves and converts the result content to specified pointer. 44 // The parameter <pointer> can be type of: struct/*struct/**struct/[]struct/[]*struct/*[]struct, etc. 45 func (c *Client) PatchVar(url string, data ...interface{}) *gvar.Var { 46 return c.RequestVar("PATCH", url, data...) 47 } 48 49 // ConnectVar sends a CONNECT request, retrieves and converts the result content to specified pointer. 50 // The parameter <pointer> can be type of: struct/*struct/**struct/[]struct/[]*struct/*[]struct, etc. 51 func (c *Client) ConnectVar(url string, data ...interface{}) *gvar.Var { 52 return c.RequestVar("CONNECT", url, data...) 53 } 54 55 // OptionsVar sends a OPTIONS request, retrieves and converts the result content to specified pointer. 56 // The parameter <pointer> can be type of: struct/*struct/**struct/[]struct/[]*struct/*[]struct, etc. 57 func (c *Client) OptionsVar(url string, data ...interface{}) *gvar.Var { 58 return c.RequestVar("OPTIONS", url, data...) 59 } 60 61 // TraceVar sends a TRACE request, retrieves and converts the result content to specified pointer. 62 // The parameter <pointer> can be type of: struct/*struct/**struct/[]struct/[]*struct/*[]struct, etc. 63 func (c *Client) TraceVar(url string, data ...interface{}) *gvar.Var { 64 return c.RequestVar("TRACE", url, data...) 65 } 66 67 // RequestVar sends request using given HTTP method and data, retrieves converts the result 68 // to specified pointer. It reads and closes the response object internally automatically. 69 // The parameter <pointer> can be type of: struct/*struct/**struct/[]struct/[]*struct/*[]struct, etc. 70 func (c *Client) RequestVar(method string, url string, data ...interface{}) *gvar.Var { 71 response, err := c.DoRequest(method, url, data...) 72 if err != nil { 73 return gvar.New(nil) 74 } 75 defer response.Close() 76 return gvar.New(response.ReadAll()) 77 }