httpclient

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2026 License: MIT Imports: 7 Imported by: 0

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