httpclient

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package httpclient provides an HTTP client with auth, retry, and pagination support.

Index

Constants

This section is empty.

Variables

View Source
var UserAgent = ""

UserAgent is the default User-Agent header value. It can be overridden by the caller.

View Source
var Version = "0.0.0-dev"

Version is the version string used in the User-Agent header. It can be overridden at build time or by the caller.

Functions

func DetectContentType

func DetectContentType(body []byte, contentType string) bool

DetectContentType attempts to determine if content is binary

func IsJSON

func IsJSON(data []byte) bool

IsJSON checks if content appears to be JSON

func RedactSensitiveHeader

func RedactSensitiveHeader(key, value string) string

RedactSensitiveHeader redacts sensitive header values

func RedactToken

func RedactToken(token string) string

RedactToken redacts sensitive parts of an authorization token

func ShouldSkipAuth

func ShouldSkipAuth(url string, headers map[string]string, skipAuth bool) bool

ShouldSkipAuth determines if authentication should be skipped

Types

type Client

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

Client wraps HTTP client functionality

func NewClient

func NewClient(tokenProvider TokenProvider, insecure bool, timeout time.Duration) *Client

NewClient creates a new HTTP client

func (*Client) Execute

func (c *Client) Execute(ctx context.Context, opts RequestOptions) (*Response, error)

Execute performs an HTTP request with the given options

type Formatter

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

Formatter handles response formatting and output

func NewFormatter

func NewFormatter(verbose bool, format string) *Formatter

NewFormatter creates a new formatter

func (*Formatter) Format

func (f *Formatter) Format(resp *Response) (string, error)

Format formats the response for output

func (*Formatter) WriteOutput

func (f *Formatter) WriteOutput(output string, outputFile string) error

WriteOutput writes the formatted output to the appropriate destination

func (*Formatter) WriteRawOutput

func (f *Formatter) WriteRawOutput(data []byte, outputFile string) error

WriteRawOutput writes raw bytes to a file or stdout

type MockTokenProvider

type MockTokenProvider struct {
	Token string
	Error error
}

MockTokenProvider is a mock implementation of TokenProvider for testing.

func (*MockTokenProvider) GetToken

func (m *MockTokenProvider) GetToken(ctx context.Context, scope string) (string, error)

GetToken returns the configured token or error.

type OutputFormat

type OutputFormat string

OutputFormat represents the output format type

const (
	FormatAuto OutputFormat = "auto"
	FormatJSON OutputFormat = "json"
	FormatRaw  OutputFormat = "raw"
)

type RequestOptions

type RequestOptions struct {
	Method          string
	URL             string
	Body            io.Reader
	Headers         map[string]string
	Scope           string
	SkipAuth        bool
	Verbose         bool
	Timeout         time.Duration
	Insecure        bool
	FollowRedirects bool
	MaxRedirects    int
	OutputFile      string
	Format          string
	TokenProvider   TokenProvider
	Binary          bool
	Retry           int
	MaxResponseSize int64
	Paginate        bool
}

RequestOptions contains options for HTTP requests

type Response

type Response struct {
	StatusCode int
	Status     string
	Headers    http.Header
	Body       []byte
	Duration   time.Duration
}

Response contains HTTP response data

type TokenProvider

type TokenProvider interface {
	GetToken(ctx context.Context, scope string) (string, error)
}

TokenProvider supplies OAuth bearer tokens for a given scope.

Jump to

Keyboard shortcuts

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