httpclient

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2026 License: MIT Imports: 4 Imported by: 0

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