netservice

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ListenAndServe

func ListenAndServe(address string, server Server, opts ...ListenAndServeOption) service.RunFunc

ListenAndServe is a shortcut for NewListener and Serve.

func NewListener

func NewListener(ctx context.Context, address string, opts ...ListenerOption) (net.Listener, error)

NewListener creates a new listener.

func Serve

func Serve(server Server, listener net.Listener, opts ...ServeOption) service.RunFunc

Serve returns a runner that serves the server through the provided listener. On context cancellation, the server tries to gracefully shutdown.

Types

type ListenAndServeOption added in v1.0.2

type ListenAndServeOption any

ListenAndServeOption allow underlying option to be of type ListenerOption or ServeOption.

type ListenerOption

type ListenerOption func(*listenerOptions) error

ListenerOption defines options applier for the listener.

func ListenWithIntermediateTLSConfig

func ListenWithIntermediateTLSConfig(certFile, keyFile string, customizeFunc ...func(*tls.Config)) ListenerOption

ListenWithIntermediateTLSConfig sets the tls configuration for tls.NewListener. "Intermediate" is defined based on this website: https://wiki.mozilla.org/Security/Server_Side_TLS.

func ListenWithKeepAlive

func ListenWithKeepAlive(keepAlive time.Duration) ListenerOption

ListenWithKeepAlive sets keepalive period.

func ListenWithModernTLSConfig

func ListenWithModernTLSConfig(certFile, keyFile string, customizeFunc ...func(*tls.Config)) ListenerOption

ListenWithModernTLSConfig sets the tls configuration for tls.NewListener. "Modern" is defined based on this website: https://wiki.mozilla.org/Security/Server_Side_TLS.

func ListenWithNetwork

func ListenWithNetwork(network string) ListenerOption

ListenWithNetwork sets the network parameter for net.Listen().

func ListenWithTLSConfig

func ListenWithTLSConfig(cfg *tls.Config) ListenerOption

ListenWithTLSConfig sets the tls configuration for tls.NewListener.

func ListenWithoutKeepAlive

func ListenWithoutKeepAlive() ListenerOption

ListenWithoutKeepAlive disables the keepalive on the listener.

type ServeOption

type ServeOption func(*serveOptions)

ServeOption defines options applier for the server.

func ServerWithServeErrorTransformer

func ServerWithServeErrorTransformer(f func(error) error) ServeOption

ServerWithServeErrorTransformer sets a function to transform serve errors.

func ServerWithShutdownErrorTransformer

func ServerWithShutdownErrorTransformer(f func(error) error) ServeOption

ServerWithShutdownErrorTransformer sets a function to transform shutdown errors.

func ServerWithShutdownTimeout added in v1.0.3

func ServerWithShutdownTimeout(timeout time.Duration) ServeOption

ServerWithShutdownTimeout sets the provider timeout to shut down.

type Server

type Server interface {
	Serve(listener net.Listener) error
	Shutdown(ctx context.Context) error
}

Server defines methods to serve and stop a network service.

Jump to

Keyboard shortcuts

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