httpclient

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BasicAuth

type BasicAuth struct {
	Username string
	Password string
}

BasicAuth holds credentials for HTTP Basic Authentication.

type Client

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

Client is an HTTP client that wraps a Doer with base URL and auth headers.

func New

func New(cfg Config) *Client

New creates a production Client from the given Config. It defaults Timeout to 30s if unset, and InsecureSkipVerify to false.

func NewWithDoer

func NewWithDoer(doer Doer, baseURL string) *Client

NewWithDoer creates a Client with an injected Doer for testing.

func (*Client) Do

func (c *Client) Do(ctx context.Context, method, path string, body interface{}) (map[string]interface{}, int, error)

Do builds an HTTP request from the base URL + path, JSON-encodes the body, executes via the Doer, and JSON-decodes the response. It returns the decoded JSON map, the HTTP status code, and any error.

type Config

type Config struct {
	BaseURL            string
	BasicAuth          *BasicAuth
	InsecureSkipVerify bool
	Timeout            time.Duration
}

Config holds all settings needed to construct a Client.

type Doer

type Doer interface {
	Do(req *http.Request) (*http.Response, error)
}

Doer abstracts HTTP execution. *http.Client satisfies this.

Jump to

Keyboard shortcuts

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