httphelper

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2023 License: MIT Imports: 3 Imported by: 6

README

httphelper

Go Reference

Helpers for Go's net/http package.

Documentation

Overview

Package httphelper contains net/http package helpers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithObject added in v0.2.0

func WithObject() func(o *HttpErrorOptions)

WithObject turns on HttpError Object reading from a HTTP response body.

Types

type HttpError

type HttpError[O any] struct {
	StatusCode int    `json:"status_code"`
	Status     string `json:"status"`
	Object     O      `json:"object,omitempty"`
}

HttpError represents a HTTP error. Object (if turned on) is read from a HTTP response body, if any.

func NewHttpError

func NewHttpError[O any](rs *http.Response, opts ...func(o *HttpErrorOptions)) (*HttpError[O], error)

NewHttpError creates HttpError from http.Response.

func (*HttpError[B]) Error

func (e *HttpError[B]) Error() string

Error implements the [error] interface.

type HttpErrorOptions added in v0.2.1

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

HttpErrorOptions contains HttpError options.

Jump to

Keyboard shortcuts

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