request

package
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 28, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BasicAuth

func BasicAuth(username, password string) string

BasicAuth generates a basic HTTP authentication string by encoding the provided username and password. The string is base64-encoded in the format "username:password".

Parameters: - username string: The username for basic authentication. - password string: The password for basic authentication.

Returns: - string: A base64-encoded string in the format "Basic <base64-encoded-credentials>".

func Call

func Call(req *http.Request, response interface{}) (*http.Response, error)

Call makes an HTTP request using the provided request object and decodes the response into the specified structure. It automatically sets the request Content-Type to application/json and decodes the JSON response body into the provided response interface.

Parameters: - req *http.Request: The prepared HTTP request to send. - response interface{}: The target structure to hold the decoded JSON response.

Returns: - *http.Response: The raw HTTP response object. - error: An error if the HTTP request or JSON decoding fails.

func ToJsonReq

func ToJsonReq(payload interface{}) (*bytes.Buffer, error)

ToJsonReq converts a Go object to a JSON-encoded HTTP request payload. It serializes the provided payload to JSON format and wraps it in a buffer for sending in HTTP requests.

Parameters: - payload interface{}: The data structure to be serialized into JSON.

Returns: - *bytes.Buffer: The JSON-encoded payload wrapped in a bytes buffer, ready to be sent in a request. - error: An error if the JSON marshalling process fails.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL