uhttp

package
v0.1.26 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2024 License: Apache-2.0 Imports: 19 Imported by: 167

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewClient

func NewClient(ctx context.Context, options ...Option) (*http.Client, error)

NewClient creates a new HTTP client that uses the given context and options to create a new transport layer.

Types

type AuthCredentials added in v0.1.23

type AuthCredentials interface {
	GetClient(ctx context.Context) (*http.Client, error)
}

type BaseHttpClient added in v0.1.24

type BaseHttpClient struct {
	HttpClient *http.Client
}

func NewBaseHttpClient added in v0.1.25

func NewBaseHttpClient(httpClient *http.Client) *BaseHttpClient

func (*BaseHttpClient) Do added in v0.1.24

func (c *BaseHttpClient) Do(req *http.Request, options ...DoOption) (*http.Response, error)

func (*BaseHttpClient) NewRequest added in v0.1.24

func (c *BaseHttpClient) NewRequest(ctx context.Context, method string, url *url.URL, options ...RequestOption) (*http.Request, error)

type BasicAuth added in v0.1.23

type BasicAuth struct {
	Username string
	Password string
}

func NewBasicAuth added in v0.1.23

func NewBasicAuth(username, password string) *BasicAuth

func (*BasicAuth) GetClient added in v0.1.23

func (b *BasicAuth) GetClient(ctx context.Context) (*http.Client, error)

type BearerAuth added in v0.1.23

type BearerAuth struct {
	Token string
}

func NewBearerAuth added in v0.1.23

func NewBearerAuth(token string) *BearerAuth

func (*BearerAuth) GetClient added in v0.1.23

func (b *BearerAuth) GetClient(ctx context.Context) (*http.Client, error)

type CreateJWTConfig added in v0.1.23

type CreateJWTConfig func(credentials []byte, scopes ...string) (*jwt.Config, error)

type DoOption added in v0.1.24

type DoOption func(*http.Response) error

func WithJSONResponse added in v0.1.24

func WithJSONResponse(response interface{}) DoOption

type HttpClient added in v0.1.24

type HttpClient interface {
	HttpClient() *http.Client
	Do(req *http.Request, options ...DoOption) (*http.Response, error)
	NewRequest(ctx context.Context, method string, url *url.URL, options ...RequestOption) (*http.Request, error)
}

type NoAuth added in v0.1.23

type NoAuth struct{}

func (*NoAuth) GetClient added in v0.1.23

func (n *NoAuth) GetClient(ctx context.Context) (*http.Client, error)

type OAuth2ClientCredentials added in v0.1.23

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

func NewOAuth2ClientCredentials added in v0.1.23

func NewOAuth2ClientCredentials(clientId, clientSecret string, tokenURL *url.URL, scopes []string) *OAuth2ClientCredentials

func (*OAuth2ClientCredentials) GetClient added in v0.1.23

func (o *OAuth2ClientCredentials) GetClient(ctx context.Context) (*http.Client, error)

type OAuth2JWT added in v0.1.23

type OAuth2JWT struct {
	Credentials     []byte
	Scopes          []string
	CreateJWTConfig CreateJWTConfig
}

func NewOAuth2JWT added in v0.1.23

func NewOAuth2JWT(credentials []byte, scopes []string, createfn CreateJWTConfig) *OAuth2JWT

func (*OAuth2JWT) GetClient added in v0.1.23

func (o *OAuth2JWT) GetClient(ctx context.Context) (*http.Client, error)

type Option

type Option interface {
	Apply(*Transport)
}

func WithLogger

func WithLogger(log bool, logger *zap.Logger) Option

WithLogger sets a logger options to the transport layer.

func WithTLSClientConfig

func WithTLSClientConfig(tlsConfig *tls.Config) Option

WithTLSClientConfig returns an Option that sets the TLS client configuration. `tlsConfig` is a structure that is used to configure a TLS client or server.

func WithUserAgent

func WithUserAgent(userAgent string) Option

WithUserAgent sets a user agent option to the transport layer.

type RequestOption added in v0.1.24

type RequestOption func() (io.ReadWriter, map[string]string, error)

func WithAcceptJSONHeader added in v0.1.24

func WithAcceptJSONHeader() RequestOption

func WithContentTypeJSONHeader added in v0.1.24

func WithContentTypeJSONHeader() RequestOption

func WithJSONBody added in v0.1.24

func WithJSONBody(body interface{}) RequestOption

type Transport

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

func NewTransport

func NewTransport(ctx context.Context, options ...Option) (*Transport, error)

NewTransport creates a new Transport, applies the options, and then cycles the transport.

func (*Transport) RoundTrip

func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error)

Jump to

Keyboard shortcuts

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