network

package
v0.0.0-...-e4f7161 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRoundTrip                 = errors.New("round trip error")
	ErrInterfacesRetrievalFailed = errors.New("retrieving interfaces failed")
)

Functions

func GetTLSConfig

func GetTLSConfig() *tls.Config

func Init

func Init(clientConf *Config, serverConf *Config)

Init should be called when the app starts, from config objects.

Types

type Address

type Address = net.Addr

type Config

type Config struct {
	// Common
	CertPath            string        `json:"certPath,omitempty"`
	KeyPath             string        `json:"keyPath,omitempty"`
	TLSMin              uint16        `json:"tlsMin,omitempty"`
	TLSHandshakeTimeout time.Duration `json:"tlsHandshakeTimeout,omitempty"`
	// Client only
	DialerTimeout      time.Duration `json:"dialerTimeout,omitempty"`
	DialerKeepAlive    time.Duration `json:"dialerKeepAlive,omitempty"`
	RootCAs            []string      `json:"rootCa,omitempty"`
	DisallowSystemRoot bool          `json:"disallowSystemRoot,omitempty"`
	// Server only
	ClientCA          string `json:"clientCa,omitempty"`
	ClientCertRequire bool   `json:"clientCertRequire,omitempty"`
	Port              uint16 `json:"port,omitempty"`

	Resolve func(pth ...string) string `json:"-"`
}

Config defines configuration to be applied to network communication, allowing to globally specify TLS certificates and minimum TLS version, timeouts, and other network properties. This should typically be marshalled from a local config file, and fed to network.Init.

type Interface

type Interface = net.Interface

type Interfaces

type Interfaces struct{}

func (*Interfaces) GetAddresses

func (obj *Interfaces) GetAddresses(onlyIPv4 bool, onlyName string) ([]Address, error)

type Network

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

Network holds network configuration for both client and server operations and provides helpers methods to retrieve TLSConfig and Transport objects.

func (*Network) TLSConfig

func (network *Network) TLSConfig() *tls.Config

TLSConfig returns a new tls.Config object populated against the configuration.

func (*Network) Transport

func (network *Network) Transport() *Transport

Transport returns a new Transport object populated against the configuration.

type Transport

type Transport struct {
	http.Transport
	TokenValue string
	TokenType  string
}

Transport implements http.Transport with a RoundTrip that has baked-in defaults, notably for GitHub It is not meant to be instantiated directly, but rather obtained through Get().Transport().

func GetTransport

func GetTransport() *Transport

func (*Transport) RoundTrip

func (adt *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