github.com/wangyougui/gf/v2@v2.6.5/net/gclient/gclient_content.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/wangyougui/gf.
     6  
     7  package gclient
     8  
     9  import (
    10  	"context"
    11  	"net/http"
    12  )
    13  
    14  // GetContent is a convenience method for sending GET request, which retrieves and returns
    15  // the result content and automatically closes response object.
    16  func (c *Client) GetContent(ctx context.Context, url string, data ...interface{}) string {
    17  	return string(c.RequestBytes(ctx, http.MethodGet, url, data...))
    18  }
    19  
    20  // PutContent is a convenience method for sending PUT request, which retrieves and returns
    21  // the result content and automatically closes response object.
    22  func (c *Client) PutContent(ctx context.Context, url string, data ...interface{}) string {
    23  	return string(c.RequestBytes(ctx, http.MethodPut, url, data...))
    24  }
    25  
    26  // PostContent is a convenience method for sending POST request, which retrieves and returns
    27  // the result content and automatically closes response object.
    28  func (c *Client) PostContent(ctx context.Context, url string, data ...interface{}) string {
    29  	return string(c.RequestBytes(ctx, http.MethodPost, url, data...))
    30  }
    31  
    32  // DeleteContent is a convenience method for sending DELETE request, which retrieves and returns
    33  // the result content and automatically closes response object.
    34  func (c *Client) DeleteContent(ctx context.Context, url string, data ...interface{}) string {
    35  	return string(c.RequestBytes(ctx, http.MethodDelete, url, data...))
    36  }
    37  
    38  // HeadContent is a convenience method for sending HEAD request, which retrieves and returns
    39  // the result content and automatically closes response object.
    40  func (c *Client) HeadContent(ctx context.Context, url string, data ...interface{}) string {
    41  	return string(c.RequestBytes(ctx, http.MethodHead, url, data...))
    42  }
    43  
    44  // PatchContent is a convenience method for sending PATCH request, which retrieves and returns
    45  // the result content and automatically closes response object.
    46  func (c *Client) PatchContent(ctx context.Context, url string, data ...interface{}) string {
    47  	return string(c.RequestBytes(ctx, http.MethodPatch, url, data...))
    48  }
    49  
    50  // ConnectContent is a convenience method for sending CONNECT request, which retrieves and returns
    51  // the result content and automatically closes response object.
    52  func (c *Client) ConnectContent(ctx context.Context, url string, data ...interface{}) string {
    53  	return string(c.RequestBytes(ctx, http.MethodConnect, url, data...))
    54  }
    55  
    56  // OptionsContent is a convenience method for sending OPTIONS request, which retrieves and returns
    57  // the result content and automatically closes response object.
    58  func (c *Client) OptionsContent(ctx context.Context, url string, data ...interface{}) string {
    59  	return string(c.RequestBytes(ctx, http.MethodOptions, url, data...))
    60  }
    61  
    62  // TraceContent is a convenience method for sending TRACE request, which retrieves and returns
    63  // the result content and automatically closes response object.
    64  func (c *Client) TraceContent(ctx context.Context, url string, data ...interface{}) string {
    65  	return string(c.RequestBytes(ctx, http.MethodTrace, url, data...))
    66  }
    67  
    68  // RequestContent is a convenience method for sending custom http method request, which
    69  // retrieves and returns the result content and automatically closes response object.
    70  func (c *Client) RequestContent(ctx context.Context, method string, url string, data ...interface{}) string {
    71  	return string(c.RequestBytes(ctx, method, url, data...))
    72  }