httpc

package
v1.11.0 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2024 License: Apache-2.0 Imports: 21 Imported by: ? 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

Index

Constants

This section is empty.

Variables

View Source
var ErrGetWithBody = errors.New("HTTP GET should not have body")

ErrGetWithBody indicates that GET request with body.

Functions

func Do

func Do(ctx context.Context, method, url string, data any) (*http.Response, error)

Do sends an HTTP request with the given arguments and returns an HTTP response. data is automatically marshal into a *httpRequest, typically it's defined in an API file.

func DoRequest

func DoRequest(r *http.Request) (*http.Response, error)

DoRequest sends an HTTP request and returns an HTTP response.

func Parse

func Parse(resp *http.Response, val any) error

Parse parses the response.

func ParseHeaders

func ParseHeaders(resp *http.Response, val any) error

ParseHeaders parses the response headers.

func ParseJsonBody

func ParseJsonBody(resp *http.Response, val any) error

ParseJsonBody parses the response body, which should be in json content type.

Types

type Option

type Option func(r *http.Request) *http.Request

Option is used to customize the *http.Client.

type Service

type Service interface {
	// Do sends an HTTP request with the given arguments and returns an HTTP response.
	Do(ctx context.Context, method, url string, data any) (*http.Response, error)
	// DoRequest sends a HTTP request to the service.
	DoRequest(r *http.Request) (*http.Response, error)
}

Service represents a remote HTTP service.

func NewService

func NewService(name string, opts ...Option) Service

NewService returns a remote service with the given name. opts are used to customize the *http.Client.

func NewServiceWithClient

func NewServiceWithClient(name string, cli *http.Client, opts ...Option) Service

NewServiceWithClient returns a remote service with the given name. opts are used to customize the *http.Client.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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