gohttp

package module
v0.0.0-...-59f7e35 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2025 License: MIT Imports: 11 Imported by: 0

README

gohttp

A simple HTTP client for Go with some features.

features

  • Automatic Retries: Exponential backoff with jitter
  • Response Decompression: Supports gzip, brotli, and deflate
  • Rate Limiting: Token bucket rate limiter
  • Context Support: Timeout and cancellation handling
  • Cookie Management: Built-in cookie jar
  • Browser Headers: Realistic user agent and headers

Documentation

Index

Constants

This section is empty.

Variables

View Source
var HEADER = map[string]string{
	"User-Agent":                "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36",
	"Accept":                    "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
	"Accept-Language":           "ko-KR,ko;q=0.9,en-US;q=0.8,en;q=0.7",
	"Accept-Encoding":           "gzip, deflate, br",
	"Connection":                "keep-alive",
	"Cache-Control":             "max-age=0",
	"Sec-Ch-Ua":                 "\"Google Chrome\";v=\"122\", \"Chromium\";v=\"122\", \"Not-A.Brand\";v=\"99\"",
	"Sec-Ch-Ua-Mobile":          "?0",
	"Sec-Ch-Ua-Platform":        "\"Windows\"",
	"Sec-Fetch-Dest":            "document",
	"Sec-Fetch-Mode":            "navigate",
	"Sec-Fetch-Site":            "none",
	"Sec-Fetch-User":            "?1",
	"Upgrade-Insecure-Requests": "1",
	"Referer":                   "https://www.google.com/",
}

Functions

This section is empty.

Types

type Client

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

func NewClient

func NewClient(ctx context.Context, options ...Option) *Client

func (Client) Context

func (c Client) Context() context.Context

func (*Client) Get

func (c *Client) Get(url string, referer ...string) (*Response, error)

func (*Client) Post

func (c *Client) Post(url, contentType string, body io.Reader, referer ...string) (*Response, error)

type Option

type Option func(*Client)

func WithRetries

func WithRetries(n int) Option

func WithTimeout

func WithTimeout(dur time.Duration) Option

type RateLimiter

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

func NewRateLimiter

func NewRateLimiter(ctx context.Context, maxTokens int) *RateLimiter

this will automatically start the process as goroutine

func (*RateLimiter) GetToken

func (rl *RateLimiter) GetToken()

type Response

type Response struct {
	Status int
	Header http.Header
	Body   []byte
}

Jump to

Keyboard shortcuts

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