network

package
v0.0.0-...-fc2e6af Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	APIListener     = "API"
	MetricsListener = "Metrics"
)

Common listener names:

View Source
const (
	APIAddress     = "localhost:8000"
	MetricsAddress = "localhost:8001"
)

Common listener addresses:

Variables

This section is empty.

Functions

func AddListenerFlags

func AddListenerFlags(set *pflag.FlagSet, name, addr string)

AddListenerFlags adds to the given flag set the flags needed to configure a network listener. It receives the name of the listerner and the default address. For example, to configure an API listener:

network.AddListenerFlags("API", "localhost:8000")

The name will be converted to lower case to generate a prefix for the flags, and will be used unchanged as a prefix for the help text. The above example will result in the following flags:

--api-listener-address string API listen address. (default "localhost:8000")
--api-listener-tls-crt string API TLS certificate in PEM format.
--api-listener-tls-key string API TLS key in PEM format.

Types

type ListenerBuilder

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

ListenerBuilder contains the data and logic needed to create a network listener. Don't create instances of this object directly, use the NewListener function instead.

func NewListener

func NewListener() *ListenerBuilder

NewListener creates a builder that can then used to configure and create a network listener.

func (*ListenerBuilder) AddTLSProtocol

func (b *ListenerBuilder) AddTLSProtocol(value string) *ListenerBuilder

AddTLSProtocol adds a protocol that will be supported during the TLS negotiation.

func (*ListenerBuilder) Build

func (b *ListenerBuilder) Build() (result net.Listener, err error)

Build uses the data stored in the builder to create a new network listener.

func (*ListenerBuilder) SetAddress

func (b *ListenerBuilder) SetAddress(value string) *ListenerBuilder

SetAddress sets the listen address. This is mandatory.

func (*ListenerBuilder) SetFlags

func (b *ListenerBuilder) SetFlags(flags *pflag.FlagSet, name string) *ListenerBuilder

SetFlags sets the command line flags that should be used to configure the listener.

The name is used to select the options when there are multiple listeners. For example, if it is 'API' then it will only take into accounts the flags starting with '--api'.

This is optional.

func (*ListenerBuilder) SetLogger

func (b *ListenerBuilder) SetLogger(value *slog.Logger) *ListenerBuilder

SetLogger sets the logger that the listener will use to send messages to the log. This is mandatory.

func (*ListenerBuilder) SetNetwork

func (b *ListenerBuilder) SetNetwork(value string) *ListenerBuilder

SetNetwork sets the network. This is optional and the default is TCP.

func (*ListenerBuilder) SetTLSCrt

func (b *ListenerBuilder) SetTLSCrt(value string) *ListenerBuilder

SetTLSCrt sets the file that contains the certificate file, in PEM format.

func (*ListenerBuilder) SetTLSKey

func (b *ListenerBuilder) SetTLSKey(value string) *ListenerBuilder

SetTLSKey sets the file that contains the key file, in PEM format.

Jump to

Keyboard shortcuts

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