httpclient

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: May 24, 2026 License: MIT Imports: 7 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 REST API integrations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthConfig

type AuthConfig struct {
	// Type is the auth type: "bearer", "basic", or "none".
	Type     string
	Token    string
	Username string
	Password string
}

AuthConfig holds authentication configuration for HTTP requests.

type Client

type Client struct {
	BaseURL    string
	HTTPClient *http.Client
	Auth       AuthConfig
}

Client is a reusable HTTP client with a fixed base URL and auth configuration.

func New

func New(baseURL string, auth AuthConfig, timeout time.Duration) *Client

New creates a Client with the given base URL, auth config, and timeout.

func (*Client) Do

func (c *Client) Do(ctx context.Context, method, path string, body any) (*http.Response, error)

Do builds and executes an HTTP request. When body is non-nil it is marshaled to JSON and Content-Type is set to application/json. The caller is responsible for reading and closing the response body.

func (*Client) DoJSON

func (c *Client) DoJSON(ctx context.Context, method, path string, body any, out any) error

DoJSON calls Do and reads the response, unmarshaling a successful body into out. If out is nil the response body is discarded. Returns an error for HTTP status >= 400.

Jump to

Keyboard shortcuts

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