http

package
v0.2.50 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultContentType = "application/json"

Variables

This section is empty.

Functions

This section is empty.

Types

type BasicAuthentication

type BasicAuthentication struct {
	Username string
	Password string
}

BasicAuthentication represents the authentication credentials using a username and password.

type CertificateAuthority

type CertificateAuthority struct {
	CAData []byte
	CAFile string
}

CertificateAuthority represents the certificate authority information.

type ClientCertificateAuthentication

type ClientCertificateAuthentication struct {
	CertData []byte
	KeyData  []byte
	CertFile string
	KeyFile  string
}

ClientCertificateAuthentication represents the authentication credentials using a client certificate.

type HttpClient

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

HttpClient represents an HTTP client for making HTTP requests. It contains the base URL for the client, the underlying HTTP client implementation, and headers to be included in each request made by the client.

func (*HttpClient) BaseUrl

func (httpClient *HttpClient) BaseUrl(baseUrl string)

BaseUrl sets the base URL for the HttpClient.

func (*HttpClient) Client

func (httpClient *HttpClient) Client(client rest.HTTPClient)

Client sets the underlying HTTP client for the HttpClient.

func (*HttpClient) Delete

func (httpClient *HttpClient) Delete(ctx context.Context, path string, queryParams ...QueryParam) ([]byte, error)

Delete sends an HTTP DELETE request to the specified path with optional query parameters.

func (*HttpClient) DeleteWithConfig

func (httpClient *HttpClient) DeleteWithConfig(ctx context.Context, config *RequestConfig) ([]byte, error)

DeleteWithConfig sends an HTTP DELETE request with a custom configuration.

func (*HttpClient) Get

func (httpClient *HttpClient) Get(ctx context.Context, path string, queryParams ...QueryParam) ([]byte, error)

Get sends an HTTP GET request to the specified path with optional query parameters.

func (*HttpClient) GetBaseUrl

func (httpClient *HttpClient) GetBaseUrl() string

GetBaseUrl returns the base URL of the HttpClient.

func (*HttpClient) GetWithConfig

func (httpClient *HttpClient) GetWithConfig(ctx context.Context, config *RequestConfig) ([]byte, error)

GetWithConfig sends an HTTP GET request with a custom configuration.

func (*HttpClient) Post

func (httpClient *HttpClient) Post(ctx context.Context, path string, body []byte, queryParams ...QueryParam) ([]byte, error)

Post sends an HTTP POST request to the specified path with the provided request body and optional query parameters.

func (*HttpClient) PostWithConfig

func (httpClient *HttpClient) PostWithConfig(ctx context.Context, config *RequestConfig) ([]byte, error)

PostWithConfig sends an HTTP POST request with a custom configuration.

func (*HttpClient) Put

func (httpClient *HttpClient) Put(ctx context.Context, path string, body []byte, queryParams ...QueryParam) ([]byte, error)

Put sends an HTTP PUT request to the specified path with the provided request body and optional query parameters.

func (*HttpClient) PutWithConfig

func (httpClient *HttpClient) PutWithConfig(ctx context.Context, config *RequestConfig) ([]byte, error)

PutWithConfig sends an HTTP PUT request with a custom configuration.

type HttpClientBuilder

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

HttpClientBuilder represents a builder for creating an HttpClient instance.

func NewHttpClientBuilder

func NewHttpClientBuilder() *HttpClientBuilder

NewHttpClientBuilder creates a new instance of HttpClientBuilder.

func (*HttpClientBuilder) Build

func (b *HttpClientBuilder) Build() (*HttpClient, error)

Build creates and returns an instance of HttpClient based on the current configuration. It returns an error if there is any issue during the creation of the client.

func (*HttpClientBuilder) ForHost

func (b *HttpClientBuilder) ForHost(host string) *HttpClientBuilder

ForHost sets the host for the HttpClientBuilder instance.

func (*HttpClientBuilder) SetInsecure

func (b *HttpClientBuilder) SetInsecure(insecure bool) *HttpClientBuilder

SetInsecure sets the insecure flag for the HttpClientBuilder instance.

func (*HttpClientBuilder) WithBasicAuth

func (b *HttpClientBuilder) WithBasicAuth(username string, password string) *HttpClientBuilder

WithBasicAuth sets the basic authentication credentials for the HttpClientBuilder instance.

func (*HttpClientBuilder) WithCertificateAuthority

func (b *HttpClientBuilder) WithCertificateAuthority(caData []byte) *HttpClientBuilder

WithCertificateAuthority sets the certificate authority data for the HttpClientBuilder instance.

func (*HttpClientBuilder) WithCertificateAuthorityFile

func (b *HttpClientBuilder) WithCertificateAuthorityFile(caFile string) *HttpClientBuilder

WithCertificateAuthorityFile sets the certificate authority file for the HttpClientBuilder instance.

func (*HttpClientBuilder) WithClientCertAuth

func (b *HttpClientBuilder) WithClientCertAuth(certData []byte, keyData []byte) *HttpClientBuilder

WithClientCertAuth sets the client certificate and key data for the HttpClientBuilder instance.

func (*HttpClientBuilder) WithClientCertAuthFiles

func (b *HttpClientBuilder) WithClientCertAuthFiles(certFile string, keyFile string) *HttpClientBuilder

WithClientCertAuthFiles sets the client certificate and key files for the HttpClientBuilder instance.

func (*HttpClientBuilder) WithContentType

func (b *HttpClientBuilder) WithContentType(accept string, contentType string) *HttpClientBuilder

WithContentType sets the accept and content type for the HttpClientBuilder instance.

func (*HttpClientBuilder) WithHeaders

func (b *HttpClientBuilder) WithHeaders(headers map[string][]string) *HttpClientBuilder

WithHeaders sets the additional headers for the HttpClientBuilder instance.

func (*HttpClientBuilder) WithHttpClientConfig

func (b *HttpClientBuilder) WithHttpClientConfig(config *HttpClientConfig) *HttpClientBuilder

WithHttpClientConfig sets the HttpClientConfig for the HttpClientBuilder instance.

func (*HttpClientBuilder) WithNtlmAuth

func (b *HttpClientBuilder) WithNtlmAuth(username string, password string, domain string) *HttpClientBuilder

WithNtlmAuth sets the NTLM authentication credentials for the HttpClientBuilder instance.

func (*HttpClientBuilder) WithOAuth2Config

func (b *HttpClientBuilder) WithOAuth2Config(tokenUrl string, clientId string, clientSecret string, scopes []string) *HttpClientBuilder

WithOAuth2Config sets the OAuth2 configuration for the HttpClientBuilder instance.

func (*HttpClientBuilder) WithToken

func (b *HttpClientBuilder) WithToken(token string) *HttpClientBuilder

WithToken sets the bearer token for the HttpClientBuilder instance.

func (*HttpClientBuilder) WithTokenFetch

func (b *HttpClientBuilder) WithTokenFetch(tokenPath string) *HttpClientBuilder

WithTokenFetch sets the token path and configures the lazy token fetch function for the HttpClientBuilder instance.

type HttpClientConfig

type HttpClientConfig struct {
	Host                            string
	Insecure                        bool
	BasicAuthentication             *BasicAuthentication
	TokenAuthentication             *TokenAuthentication
	NtlmAuthentication              *NtlmAuthentication
	OAuth2Authentication            *OAuth2Authentication
	ClientCertificateAuthentication *ClientCertificateAuthentication
	CertificateAuthority            *CertificateAuthority
	ProxyHost                       string
	ProxyPort                       string
	ProxyUsername                   string
	ProxyPassword                   string
	ProxyDomain                     string
}

HttpClientConfig represents the configuration options for the HttpClient.

type NtlmAuthentication

type NtlmAuthentication struct {
	Username string
	Password string
	Domain   string
}

NtlmAuthentication represents the NTLM authentication credentials using a username, password, and domain.

type OAuth2Authentication

type OAuth2Authentication struct {
	ClientID     string
	ClientSecret string
	Scopes       []string
	TokenURL     string
}

OAuth2Authentication represents the OAuth2 authentication credentials using a client ID, client secret, scopes, and token URL.

type QueryParam

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

QueryParam represents a query parameter used in HTTP requests.

func (*QueryParam) Pair

func (q *QueryParam) Pair(key string, value string)

Pair sets the key-value pair for the QueryParam.

type RequestConfig

type RequestConfig struct {
	Body        []byte
	Headers     map[string][]string
	Path        string
	QueryParams []QueryParam
	// contains filtered or unexported fields
}

RequestConfig represents a configuration for an HTTP request. It contains the HTTP method, request body, headers, endpoint path, and query parameters to be included in the request.

type TokenAuthentication

type TokenAuthentication struct {
	BearerToken string
}

TokenAuthentication represents the authentication credentials using a bearer token.

Jump to

Keyboard shortcuts

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