httpclient

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2026 License: MIT Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package httpclient provides a shared HTTP client for all external API calls. The client is safe for concurrent use and reuses connections. Call Init once during startup to set the timeout; the default is 10s.

Index

Constants

View Source
const MaxResponseSize = 1 << 20

MaxResponseSize limits HTTP response bodies to 1 MB to prevent OOM.

Variables

This section is empty.

Functions

func Do

func Do(req *http.Request) (*http.Response, error)

Do executes an HTTP request using the shared client.

func GetJSON

func GetJSON(url string) ([]byte, error)

GetJSON performs a GET request and returns the response body as bytes. Returns an error for non-2xx status codes.

func Init

func Init(timeout time.Duration)

Init creates a new HTTP client with the given timeout. Must be called once during startup before any external calls.

func Truncate

func Truncate(s string, maxLen int) string

Truncate shortens a string to maxLen characters, appending "..." if truncated.

Types

This section is empty.

Jump to

Keyboard shortcuts

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