hc

package module
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2023 License: MIT Imports: 6 Imported by: 0

README

HTTP/2 Client (hc)

The hc package provides a user-friendly HTTP/2 client for Go. It supports all the standard HTTP methods (GET, POST, PUT, DELETE) and has built-in compression and JSON handling.

Features

  • HTTP/2 support.
  • Built-in gzip compression for request data.
  • Utility functions for common actions.
  • Enhanced JSON support for sending and receiving data.

Installation

go get your-repo-path/hc

Making Requests

For standard requests:

err := c.Get("https://example.com")
if err != nil {
log.Fatal(err)
}

err = c.Post("https://example.com", []byte("your data here"))
if err != nil {
log.Fatal(err)
}

err = c.Put("https://example.com", []byte("your data here"))
if err != nil {
log.Fatal(err)
}

err = c.Delete("https://example.com")
if err != nil {
log.Fatal(err)
}

For JSON requests:

data := map[string]string{"key": "value"}
err = c.PostJson("https://example.com", data)
if err != nil {
log.Fatal(err)
}

Accessing Response Data

Check the status code:


statusCode := c.Status()
statusText := c.StatusText()

Read JSON data:

var responseStruct YourStructType
err := c.ReadJson(&responseStruct)
if err != nil {
    log.Fatal(err)
}

Note

Always make sure to check the error return after making a request before you access any other utility functions. This ensures that the request was successful and that the data is available for extraction.

Contributing

Contributions are welcome! Please fork the repository and open a pull request with your changes, or open an issue with any suggestions, bugs, or feedback.

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecompressGzip

func DecompressGzip(resp *http.Response) ([]byte, error)

func ReadResponseBody

func ReadResponseBody(resp *http.Response) ([]byte, error)

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func New

func New() *Client

func (*Client) Delete

func (c *Client) Delete(url string) ([]byte, error)

func (*Client) Get

func (c *Client) Get(url string) ([]byte, error)

func (*Client) Header added in v1.0.3

func (c *Client) Header() http.Header

func (*Client) Post

func (c *Client) Post(url string, data []byte) ([]byte, error)

func (*Client) PostJson

func (c *Client) PostJson(url string, data interface{}) ([]byte, error)

func (*Client) Put

func (c *Client) Put(url string, data []byte) ([]byte, error)

func (*Client) PutJson

func (c *Client) PutJson(url string, data interface{}) ([]byte, error)

func (*Client) ReadJson

func (c *Client) ReadJson(body []byte, v interface{}) error

func (*Client) Status

func (c *Client) Status() int

func (*Client) StatusText

func (c *Client) StatusText() string

Jump to

Keyboard shortcuts

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