http

package
v0.0.0-...-a1c8992 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2026 License: Apache-2.0 Imports: 21 Imported by: 545

Documentation

Index

Constants

View Source
const (
	// InsecureTransport used to get the insecure http Transport
	InsecureTransport = iota
	// SecureTransport used to get the external secure http Transport
	SecureTransport
)

Variables

This section is empty.

Functions

func AddTracingWithGlobalTransport

func AddTracingWithGlobalTransport()

func GetHTTPTransport

func GetHTTPTransport(opts ...TransportOption) http.RoundTripper

GetHTTPTransport returns HttpTransport based on insecure configuration and CA certificate.

Priority:

  1. Custom CA certificate (if provided) - creates a new transport with custom CA
  2. Insecure mode (if enabled) - returns shared transport that skips TLS verification
  3. Default - returns shared transport that uses system CA pool

Backward Compatibility: Existing Harbor installations that rely on system-level CA trust stores will continue to work after upgrade. The custom CA certificate feature is optional, and when no custom CA is provided, the system CA pool is used (option 3 above).

func GetInternalCertPair

func GetInternalCertPair() (tls.Certificate, error)

GetInternalCertPair used to get internal cert and key pair from environment

func GetInternalTLSConfig

func GetInternalTLSConfig() (*tls.Config, error)

GetInternalTLSConfig return a tls.Config for internal https communicate

func InternalEnableVerifyClientCert

func InternalEnableVerifyClientCert() bool

InternalEnableVerifyClientCert returns true if mTLS enabled

func InternalTLSEnabled

func InternalTLSEnabled() bool

InternalTLSEnabled returns true if internal TLS enabled

func NewServerTLSConfig

func NewServerTLSConfig() *tls.Config

NewServerTLSConfig returns a modern tls config, refer to https://blog.cloudflare.com/exposing-go-on-the-internet/

func NewTransport

func NewTransport(opts ...func(*http.Transport)) http.RoundTripper

NewTransport returns a new http.Transport with the specified options

func ValidateCACertificate

func ValidateCACertificate(caCert string) error

ValidateCACertificate validates whether the provided CA certificate string contains at least one valid PEM-encoded x509 certificate.

func WithCustomCACert

func WithCustomCACert(caCert string) func(*http.Transport)

WithCustomCACert returns a TransportOption that configures custom CA certificates (supports chains) The custom CA certificates are appended to the system CA pool, so both system CAs and custom CAs are trusted.

func WithInsecureSkipVerify

func WithInsecureSkipVerify(skipVerify bool) func(*http.Transport)

WithInsecureSkipVerify returns a TransportOption that configures the transport to skip verification of the server's certificate

func WithInternalTLSConfig

func WithInternalTLSConfig() func(*http.Transport)

WithInternalTLSConfig returns a TransportOption that configures the transport to use the internal TLS configuration

Types

type Client

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

Client is a util for common HTTP operations, such Get, Head, Post, Put and Delete. Use Do instead if those methods can not meet your requirement

func NewClient

func NewClient(c *http.Client, modifiers ...modifier.Modifier) *Client

NewClient creates an instance of Client. Use net/http.Client as the default value if c is nil. Modifiers modify the request before sending it.

func (*Client) Delete

func (c *Client) Delete(url string) error

Delete ...

func (*Client) Do

func (c *Client) Do(req *http.Request) (*http.Response, error)

Do ...

func (*Client) Get

func (c *Client) Get(url string, v ...any) error

Get ...

func (*Client) GetAndIteratePagination

func (c *Client) GetAndIteratePagination(endpoint string, v any) error

GetAndIteratePagination iterates the pagination header and returns all resources The parameter "v" must be a pointer to a slice

func (*Client) GetClient

func (c *Client) GetClient() *http.Client

GetClient returns the http.Client

func (*Client) Head

func (c *Client) Head(url string) error

Head ...

func (*Client) Post

func (c *Client) Post(url string, v ...any) error

Post ...

func (*Client) Put

func (c *Client) Put(url string, v ...any) error

Put ...

type Error

type Error struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

Error wrap HTTP status code and message as an error

func (*Error) Error

func (e *Error) Error() string

Error ...

func (*Error) String

func (e *Error) String() string

String wraps the error msg to the well formatted error message

type TransportConfig

type TransportConfig struct {
	Insecure      bool
	CACertificate string
}

TransportConfig is the configuration for http transport

type TransportOption

type TransportOption func(*TransportConfig)

TransportOption is the option for http transport

func WithCACert

func WithCACert(caCert string) TransportOption

WithCACert returns a TransportOption that configures custom CA certificate

func WithInsecure

func WithInsecure(skipVerify bool) TransportOption

WithInsecure returns a TransportOption that configures the transport to skip verification of the server's certificate

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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