mainutil

package
v0.6.5 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2022 License: Apache-2.0 Imports: 46 Imported by: 0

Documentation

Overview

Package mainutil provides miscellaneous tools for implementing the main() function of long-lived HTTP and gRPC servers.

As with roxyutil, it is undecided how much (if any) of the mainutil API will remain available outside of the Roxy project once Roxy reaches v1.0.0.

Index

Constants

View Source
const (
	// ConnContextKey is a context.Context key for *ConnContext.
	ConnContextKey = contextKey("roxy.ConnContext")

	// RequestContextKey is a context.Context key for *RequestContext (app-specific).
	RequestContextKey = contextKey("roxy.RequestContext")
)

Variables

View Source
var ErrOperationFailed = errors.New("operation failed")

ErrOperationFailed is a generic error for any failed operation. Details should be provided via error wrapping.

Functions

func AppVersion added in v0.4.3

func AppVersion() string

AppVersion returns the application version.

func CancelRootContext

func CancelRootContext()

CancelRootContext cancels the root context.

func DoneLogging

func DoneLogging()

DoneLogging does end-of-program cleanup on the logging subsystem.

func InitContext

func InitContext()

InitContext initializes the root context.

The caller must ensure that CancelRootContext gets called at least once by the end of the program's lifecycle.

func InitLogging

func InitLogging()

InitLogging processes the logging flags and sets up log.Logger.

The caller must ensure that DoneLogging gets called by the end of the program's lifecycle.

func InitVersion added in v0.4.3

func InitVersion()

InitVersion processes the -V/--version flag.

func MakeBaseContextFunc added in v0.4.4

func MakeBaseContextFunc() func(net.Listener) context.Context

MakeBaseContextFunc returns a "net/http".(*Server).BaseContextFunc that returns the root context.

func MakeConnContextFunc added in v0.4.4

func MakeConnContextFunc(name string) func(context.Context, net.Conn) context.Context

MakeConnContextFunc returns a "net/http".(*Server).ConnContextFunc that prepares a *ConnContext and calls WithConnContext.

func NewDummyZapConfig

func NewDummyZapConfig() *zap.Config

NewDummyZapConfig returns a *zap.Config that logs to zerolog.

func RegisterLoggingFlags added in v0.4.3

func RegisterLoggingFlags()

RegisterLoggingFlags registers the flags for controlling log output.

func RegisterVersionFlag added in v0.4.3

func RegisterVersionFlag()

RegisterVersionFlag registers the -V/--version flag.

func RootContext

func RootContext() context.Context

RootContext returns the root context.

func RotateLogs

func RotateLogs(ctx context.Context) error

RotateLogs rotates the logfile, if that operation makes sense in the current logging configuration.

func RoxyVersion added in v0.4.3

func RoxyVersion() string

RoxyVersion returns the version of Roxy itself.

func SetAppVersion added in v0.4.3

func SetAppVersion(version string)

SetAppVersion changes the application version.

func WithConnContext added in v0.4.4

func WithConnContext(ctx context.Context, cc *ConnContext) context.Context

WithConnContext attaches the given *ConnContext to the context.

Types

type ATCAnnounceConfig

type ATCAnnounceConfig struct {
	ATCClientConfig
	ServiceName string
	Location    string
	UniqueID    string
	NamedPort   string
}

ATCAnnounceConfig represents the configuration for an *atcclient.ATCClient, plus the fields needed to call announcer.NewATC.

func (ATCAnnounceConfig) AddTo

AddTo adds this configuration to the provided Announcer.

func (ATCAnnounceConfig) AppendTo

func (cfg ATCAnnounceConfig) AppendTo(out *strings.Builder)

AppendTo appends the string representation to the given Builder.

func (*ATCAnnounceConfig) FromJSON added in v0.4.7

func (cfg *ATCAnnounceConfig) FromJSON(alt *ATCAnnounceConfigJSON) error

FromJSON converts the object's JSON doppelgänger into the object.

func (ATCAnnounceConfig) MarshalJSON

func (cfg ATCAnnounceConfig) MarshalJSON() ([]byte, error)

MarshalJSON fulfills json.Marshaler.

func (*ATCAnnounceConfig) Parse

func (cfg *ATCAnnounceConfig) Parse(str string) error

Parse parses the string representation.

func (*ATCAnnounceConfig) PostProcess added in v0.4.7

func (cfg *ATCAnnounceConfig) PostProcess() error

PostProcess performs data integrity checks and input post-processing.

func (ATCAnnounceConfig) String

func (cfg ATCAnnounceConfig) String() string

String returns the string representation.

func (ATCAnnounceConfig) ToJSON added in v0.4.7

ToJSON converts the object to its JSON doppelgänger.

func (*ATCAnnounceConfig) UnmarshalJSON

func (cfg *ATCAnnounceConfig) UnmarshalJSON(raw []byte) error

UnmarshalJSON fulfills json.Unmarshaler.

type ATCAnnounceConfigJSON added in v0.4.7

type ATCAnnounceConfigJSON struct {
	ATCClientConfigJSON
	ServiceName string `json:"serviceName"`
	Location    string `json:"location"`
	UniqueID    string `json:"uniqueID"`
	NamedPort   string `json:"namedPort"`
}

ATCAnnounceConfigJSON represents the JSON doppelgänger of an ATCAnnounceConfig.

type ATCClientConfig

type ATCClientConfig struct {
	GRPCClientConfig
}

ATCClientConfig represents the configuration for an *atcclient.ATCClient.

func (ATCClientConfig) AppendTo added in v0.4.7

func (cfg ATCClientConfig) AppendTo(out *strings.Builder)

AppendTo appends the string representation to the given Builder.

func (*ATCClientConfig) FromJSON added in v0.4.7

func (cfg *ATCClientConfig) FromJSON(alt *ATCClientConfigJSON) error

FromJSON converts the object's JSON doppelgänger into the object.

func (ATCClientConfig) MarshalJSON added in v0.4.7

func (cfg ATCClientConfig) MarshalJSON() ([]byte, error)

MarshalJSON fulfills json.Marshaler.

func (ATCClientConfig) NewClient

func (cfg ATCClientConfig) NewClient(ctx context.Context) (*atcclient.ATCClient, error)

NewClient constructs the configured *atcclient.ATCClient and dials the ATC server.

func (*ATCClientConfig) Parse added in v0.4.7

func (cfg *ATCClientConfig) Parse(str string) error

Parse parses the string representation.

func (*ATCClientConfig) PostProcess added in v0.4.7

func (cfg *ATCClientConfig) PostProcess() error

PostProcess performs data integrity checks and input post-processing.

func (ATCClientConfig) String added in v0.4.7

func (cfg ATCClientConfig) String() string

String returns the string representation.

func (ATCClientConfig) ToJSON added in v0.4.7

func (cfg ATCClientConfig) ToJSON() *ATCClientConfigJSON

ToJSON converts the object to its JSON doppelgänger.

func (*ATCClientConfig) UnmarshalJSON added in v0.4.7

func (cfg *ATCClientConfig) UnmarshalJSON(raw []byte) error

UnmarshalJSON fulfills json.Unmarshaler.

type ATCClientConfigJSON added in v0.4.7

type ATCClientConfigJSON struct {
	GRPCClientConfigJSON
}

ATCClientConfigJSON represents the JSON doppelgänger of an ATCClientConfig.

type CertKeyError added in v0.4.7

type CertKeyError struct {
	CertPath string
	KeyPath  string
	Err      error
}

CertKeyError indicates a problem while loading an X.509 certificate/key pair.

func (CertKeyError) Error added in v0.4.7

func (err CertKeyError) Error() string

Error fulfills the error interface.

func (CertKeyError) Unwrap added in v0.4.7

func (err CertKeyError) Unwrap() error

Unwrap returns the underlying cause of this error.

type CertPoolError added in v0.4.7

type CertPoolError struct {
	Path string
	Err  error
}

CertPoolError indicates a problem while loading an X.509 certificate pool.

func (CertPoolError) Error added in v0.4.7

func (err CertPoolError) Error() string

Error fulfills the error interface.

func (CertPoolError) Unwrap added in v0.4.7

func (err CertPoolError) Unwrap() error

Unwrap returns the underlying cause of this error.

type ConnContext added in v0.4.4

type ConnContext struct {
	Context    context.Context
	Logger     zerolog.Logger
	Subsystem  string
	LocalAddr  net.Addr
	RemoteAddr net.Addr
}

ConnContext is data associated with each incoming net.Conn of an http.Server.

func GetConnContext added in v0.4.4

func GetConnContext(ctx context.Context) *ConnContext

GetConnContext retrieves the associated *ConnContext.

type EtcdAnnounceConfig

type EtcdAnnounceConfig struct {
	EtcdConfig
	Path      string
	Hostname  string
	NamedPort string
	Format    announcer.Format
}

EtcdAnnounceConfig represents the configuration for an etcd.io *v3.Client, plus the fields needed to call announcer.NewEtcd.

func (EtcdAnnounceConfig) AddTo

func (cfg EtcdAnnounceConfig) AddTo(etcd *v3.Client, a *announcer.Announcer) error

AddTo adds this configuration to the provided Announcer.

func (EtcdAnnounceConfig) AppendTo

func (cfg EtcdAnnounceConfig) AppendTo(out *strings.Builder)

AppendTo appends the string representation to the given Builder.

func (*EtcdAnnounceConfig) FromJSON added in v0.4.7

func (cfg *EtcdAnnounceConfig) FromJSON(alt *EtcdAnnounceConfigJSON) error

FromJSON converts the object's JSON doppelgänger into the object.

func (EtcdAnnounceConfig) MarshalJSON

func (cfg EtcdAnnounceConfig) MarshalJSON() ([]byte, error)

MarshalJSON fulfills json.Marshaler.

func (*EtcdAnnounceConfig) Parse

func (cfg *EtcdAnnounceConfig) Parse(str string) error

Parse parses the string representation.

func (*EtcdAnnounceConfig) PostProcess added in v0.4.7

func (cfg *EtcdAnnounceConfig) PostProcess() error

PostProcess performs data integrity checks and input post-processing.

func (EtcdAnnounceConfig) String

func (cfg EtcdAnnounceConfig) String() string

String returns the string representation.

func (EtcdAnnounceConfig) ToJSON added in v0.4.7

ToJSON converts the object to its JSON doppelgänger.

func (*EtcdAnnounceConfig) UnmarshalJSON

func (cfg *EtcdAnnounceConfig) UnmarshalJSON(raw []byte) error

UnmarshalJSON fulfills json.Unmarshaler.

type EtcdAnnounceConfigJSON added in v0.4.7

type EtcdAnnounceConfigJSON struct {
	EtcdConfigJSON
	Path      string           `json:"path"`
	Hostname  string           `json:"hostname"`
	NamedPort string           `json:"namedPort"`
	Format    announcer.Format `json:"format"`
}

EtcdAnnounceConfigJSON represents the JSON doppelgänger of an EtcdAnnounceConfig.

type EtcdConfig

type EtcdConfig struct {
	Enabled          bool
	Endpoints        []string
	TLS              TLSClientConfig
	Username         string
	Password         string
	DialTimeout      time.Duration
	KeepAlive        time.Duration
	KeepAliveTimeout time.Duration
}

EtcdConfig represents the configuration for an etcd.io *v3.Client.

func (EtcdConfig) AppendTo

func (cfg EtcdConfig) AppendTo(out *strings.Builder)

AppendTo appends the string representation to the given Builder.

func (EtcdConfig) Connect

func (cfg EtcdConfig) Connect(ctx context.Context) (*v3.Client, error)

Connect constructs the configured etcd.io *v3.Client and dials the etcd cluster.

func (*EtcdConfig) FromJSON added in v0.4.7

func (cfg *EtcdConfig) FromJSON(alt *EtcdConfigJSON) error

FromJSON converts the object's JSON doppelgänger into the object.

func (EtcdConfig) MarshalJSON

func (cfg EtcdConfig) MarshalJSON() ([]byte, error)

MarshalJSON fulfills json.Marshaler.

func (*EtcdConfig) Parse

func (cfg *EtcdConfig) Parse(str string) error

Parse parses the string representation.

func (*EtcdConfig) PostProcess added in v0.4.7

func (cfg *EtcdConfig) PostProcess() error

PostProcess performs data integrity checks and input post-processing.

func (EtcdConfig) String

func (cfg EtcdConfig) String() string

String returns the string representation.

func (EtcdConfig) ToJSON added in v0.4.7

func (cfg EtcdConfig) ToJSON() *EtcdConfigJSON

ToJSON converts the object to its JSON doppelgänger.

func (*EtcdConfig) UnmarshalJSON

func (cfg *EtcdConfig) UnmarshalJSON(raw []byte) error

UnmarshalJSON fulfills json.Unmarshaler.

type EtcdConfigJSON added in v0.4.7

type EtcdConfigJSON struct {
	Endpoints        []string             `json:"endpoints"`
	TLS              *TLSClientConfigJSON `json:"tls,omitempty"`
	Username         string               `json:"username,omitempty"`
	Password         string               `json:"password,omitempty"`
	DialTimeout      time.Duration        `json:"dialTimeout,omitempty"`
	KeepAlive        time.Duration        `json:"keepAlive,omitempty"`
	KeepAliveTimeout time.Duration        `json:"keepAliveTimeout,omitempty"`
}

EtcdConfigJSON represents the JSON doppelgänger of an EtcdConfig.

type ExitFunc added in v0.5.0

type ExitFunc func(ctx context.Context) error

ExitFunc is the callback type for OnExit hooks.

type GRPCClientConfig

type GRPCClientConfig struct {
	Enabled bool
	Target  roxyresolver.Target
	TLS     TLSClientConfig
}

GRPCClientConfig represents the configuration for a *grpc.ClientConn.

func (GRPCClientConfig) AppendTo

func (cfg GRPCClientConfig) AppendTo(out *strings.Builder)

AppendTo appends the string representation to the given Builder.

func (GRPCClientConfig) Dial

func (cfg GRPCClientConfig) Dial(ctx context.Context, opts ...grpc.DialOption) (*grpc.ClientConn, error)

Dial dials the configured gRPC server.

func (*GRPCClientConfig) FromJSON added in v0.4.7

func (cfg *GRPCClientConfig) FromJSON(alt *GRPCClientConfigJSON) error

FromJSON converts the object's JSON doppelgänger into the object.

func (GRPCClientConfig) MarshalJSON

func (cfg GRPCClientConfig) MarshalJSON() ([]byte, error)

MarshalJSON fulfills json.Marshaler.

func (*GRPCClientConfig) Parse

func (cfg *GRPCClientConfig) Parse(str string) error

Parse parses the string representation.

func (*GRPCClientConfig) PostProcess added in v0.4.7

func (cfg *GRPCClientConfig) PostProcess() error

PostProcess performs data integrity checks and input post-processing.

func (GRPCClientConfig) String

func (cfg GRPCClientConfig) String() string

String returns the string representation.

func (GRPCClientConfig) ToJSON added in v0.4.7

func (cfg GRPCClientConfig) ToJSON() *GRPCClientConfigJSON

ToJSON converts the object to its JSON doppelgänger.

func (*GRPCClientConfig) UnmarshalJSON

func (cfg *GRPCClientConfig) UnmarshalJSON(raw []byte) error

UnmarshalJSON fulfills json.Unmarshaler.

type GRPCClientConfigJSON added in v0.4.7

type GRPCClientConfigJSON struct {
	Target string               `json:"target"`
	TLS    *TLSClientConfigJSON `json:"tls,omitempty"`
}

GRPCClientConfigJSON represents the JSON doppelgänger of an GRPCClientConfig.

type HealthWatchFunc added in v0.5.0

type HealthWatchFunc func(subsystemName string, isHealthy bool, isStopped bool)

HealthWatchFunc is the callback type for observing changes in health status.

type HealthWatchID added in v0.5.0

type HealthWatchID uint32

HealthWatchID tracks a registered HealthWatchFunc callback.

type ListenConfig

type ListenConfig struct {
	Enabled bool
	Network string
	Address string
	TLS     TLSServerConfig
}

ListenConfig represents the configuration for a net.Listener socket with optional TLS.

func (ListenConfig) AppendTo

func (cfg ListenConfig) AppendTo(out *strings.Builder)

AppendTo appends the string representation to the given Builder.

func (*ListenConfig) FromJSON added in v0.4.7

func (cfg *ListenConfig) FromJSON(alt *ListenConfigJSON) error

FromJSON converts the object's JSON doppelgänger into the object.

func (ListenConfig) Listen

func (cfg ListenConfig) Listen(ctx context.Context) (net.Listener, error)

Listen creates the configured net.Listener.

func (ListenConfig) ListenNoTLS added in v0.4.5

func (cfg ListenConfig) ListenNoTLS(ctx context.Context) (net.Listener, error)

ListenNoTLS creates the configured net.Listener. TLS handshaking is not added automatically.

func (ListenConfig) MarshalJSON

func (cfg ListenConfig) MarshalJSON() ([]byte, error)

MarshalJSON fulfills json.Marshaler.

func (*ListenConfig) Parse

func (cfg *ListenConfig) Parse(str string) error

Parse parses the string representation.

func (*ListenConfig) PostProcess added in v0.4.7

func (cfg *ListenConfig) PostProcess() error

PostProcess performs data integrity checks and input post-processing.

func (ListenConfig) String

func (cfg ListenConfig) String() string

String returns the string representation.

func (ListenConfig) ToJSON added in v0.4.7

func (cfg ListenConfig) ToJSON() *ListenConfigJSON

ToJSON converts the object to its JSON doppelgänger.

func (*ListenConfig) UnmarshalJSON

func (cfg *ListenConfig) UnmarshalJSON(raw []byte) error

UnmarshalJSON fulfills json.Unmarshaler.

type ListenConfigJSON added in v0.4.7

type ListenConfigJSON struct {
	Network string               `json:"network"`
	Address string               `json:"address"`
	TLS     *TLSServerConfigJSON `json:"tls,omitempty"`
}

ListenConfigJSON represents the JSON doppelgänger of an ListenConfig.

type MissingOptionValueError added in v0.4.7

type MissingOptionValueError struct{}

MissingOptionValueError indicates that an option was found with the value elided, but eliding the value doesn't make sense for that option.

func (MissingOptionValueError) Error added in v0.4.7

Error fulfills the error interface.

type MultiServer

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

MultiServer is a framework that tracks state for long-running servers. It remembers which steps need to execute at which phase of the server's lifetime, then calls those steps as needed (with parallelism when appropriate).

It is most useful for keeping track of multiple http.Server and grpc.Server instances running in parallel on different net.Listeners. It also automates signal management and communication with Systemd.

func (*MultiServer) AddAnnouncer added in v0.5.0

func (m *MultiServer) AddAnnouncer(ann *announcer.Announcer, r *membership.Roxy)

AddAnnouncer registers an Announcer and the address to be announced. This will arrange for invoke Announcer.Announce to run in an OnPreRun hook, for Announcer.Withdraw to run in an OnPreShutdown hook, and for Announcer.Close to run in an OnExit hook.

AddAnnouncer MUST NOT be called after Run has been called.

func (*MultiServer) AddGRPCServer

func (m *MultiServer) AddGRPCServer(name string, server *grpc.Server, listen net.Listener)

AddGRPCServer registers a gRPC server. This will arrange for the Run method to invoke server.Serve(listen), and for Shutdown to invoke server.GracefulStop() or server.Stop(), as appropriate.

AddGRPCServer MUST NOT be called after Run has been called.

func (*MultiServer) AddHTTPServer

func (m *MultiServer) AddHTTPServer(name string, server *http.Server, listen net.Listener)

AddHTTPServer registers an HTTP(S) server. This will arrange for the Run method to invoke server.Serve(listen), and for Shutdown to invoke server.Shutdown(ctx) or server.Close(), as appropriate.

AddHTTPServer MUST NOT be called after Run has been called.

func (*MultiServer) CancelWatchHealth added in v0.5.0

func (m *MultiServer) CancelWatchHealth(id HealthWatchID)

CancelWatchHealth unregisters a callback.

func (*MultiServer) Done added in v0.6.0

func (m *MultiServer) Done() <-chan struct{}

Done returns a channel that will close as soon as the shutdown process is triggered.

func (*MultiServer) GetHealth added in v0.5.0

func (m *MultiServer) GetHealth(subsystemName string) (isHealthy bool, found bool)

GetHealth retrieves the health status of the named subsystem.

func (*MultiServer) Go

func (m *MultiServer) Go(ctx context.Context, fn RunFunc)

Go runs a function in a goroutine. The Run method will not return until after fn has terminated.

func (*MultiServer) HealthServer added in v0.5.0

func (m *MultiServer) HealthServer() grpc_health_v1.HealthServer

HealthServer returns an implementation of grpc_health_v1.HealthServer that uses the health status reported to this MultiServer.

func (*MultiServer) OnExit

func (m *MultiServer) OnExit(fn ExitFunc)

OnExit registers a function to execute just before Run returns.

OnExit hooks are called in LIFO (Last In, First Out) order.

OnExit MUST NOT be called after Run has been called.

func (*MultiServer) OnPreRun added in v0.5.0

func (m *MultiServer) OnPreRun(fn PreRunFunc)

OnPreRun registers a function to execute when Run is called. Each such function will be called serially before any OnRun hooks execute. If any such function returns an error, Run will exit immediately with an error.

OnPreRun hooks are called in FIFO (First In, First Out) order.

OnPreRun MUST NOT be called after Run has been called.

func (*MultiServer) OnPreShutdown added in v0.5.0

func (m *MultiServer) OnPreShutdown(fn PreShutdownFunc)

OnPreShutdown registers a function to execute when SIGINT/SIGTERM are received or when Shutdown is called. Each such function will be called serially before any OnShutdown hooks execute.

OnPreShutdown hooks are called in LIFO (Last In, First Out) order.

OnPreShutdown MUST NOT be called after Run has been called.

func (*MultiServer) OnReload

func (m *MultiServer) OnReload(fn ReloadFunc)

OnReload registers a function to execute when SIGHUP is received or when Reload is called.

OnReload hooks are called in FIFO (First In, First Out) order.

OnReload MUST NOT be called after Run has been called.

func (*MultiServer) OnRun

func (m *MultiServer) OnRun(fn RunFunc)

OnRun registers a function to execute in a goroutine when Run is called.

OnRun hooks are called in FIFO (First In, First Out) order.

OnRun MUST NOT be called after Run has been called.

func (*MultiServer) OnShutdown

func (m *MultiServer) OnShutdown(fn ShutdownFunc)

OnShutdown registers a function to execute in a goroutine when SIGINT/SIGTERM are received or when Shutdown is called.

The function will be called with a bool argument, alreadyTermed. If true, then this is the second attempt to shut down the server, and the user is potentially getting impatient. If false, a graceful shutdown should be attempted.

OnShutdown hooks are called in LIFO (Last In, First Out) order.

OnShutdown MUST NOT be called after Run has been called.

func (*MultiServer) Reload

func (m *MultiServer) Reload(ctx context.Context) error

Reload triggers a server reload. It may be called from any thread.

func (*MultiServer) Run

func (m *MultiServer) Run(ctx context.Context) error

Run runs the MultiServer. It does not return until all registered servers have been fully shut down, all goroutines have exited, and all OnExit hooks have completed.

func (*MultiServer) SetHealth added in v0.5.0

func (m *MultiServer) SetHealth(subsystemName string, isHealthy bool)

SetHealth changes the health status for the named subsystem. If the subsystem does not yet exist, it is automatically created.

func (*MultiServer) Shutdown

func (m *MultiServer) Shutdown(ctx context.Context, graceful bool) error

Shutdown triggers a server shutdown. It may be called from any thread.

If graceful is true, then only graceful shutdown techniques will be considered. If graceful is false, then forceful techniques will be considered. Even if graceful is true, a forceful shutdown will be triggered if the graceful shutdown phase takes longer than 5 seconds.

func (*MultiServer) WatchHealth added in v0.5.0

func (m *MultiServer) WatchHealth(fn HealthWatchFunc) HealthWatchID

WatchHealth registers a callback that will receive a snapshot of the current health status plus a subscription to all future health status changes.

type OptionError added in v0.4.7

type OptionError struct {
	Name     string
	Value    string
	Err      error
	Complete bool
}

OptionError indicates an error while parsing options.

func (OptionError) Error added in v0.4.7

func (err OptionError) Error() string

Error fulfills the error interface.

func (OptionError) Unwrap added in v0.4.7

func (err OptionError) Unwrap() error

Unwrap returns the underlying cause of this error.

type PreRunFunc added in v0.5.0

type PreRunFunc func(ctx context.Context) error

PreRunFunc is the callback type for OnPreRun hooks.

type PreShutdownFunc added in v0.5.0

type PreShutdownFunc func(ctx context.Context) error

PreShutdownFunc is the callback type for OnPreShutdown hooks.

type PromLoggerBridge

type PromLoggerBridge struct{}

PromLoggerBridge is a promhttp.Logger that forwards to zerolog.

func (PromLoggerBridge) Println

func (PromLoggerBridge) Println(v ...interface{})

Println fulfills promhttp.Logger.

type ReloadFunc added in v0.5.0

type ReloadFunc func(ctx context.Context) error

ReloadFunc is the callback type for OnReload hooks.

type RotatingLogWriter

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

RotatingLogWriter is an io.WriteCloser that can close and re-open its output file, for logrotate(8) and the like.

func NewRotatingLogWriter

func NewRotatingLogWriter(fileName string) (*RotatingLogWriter, error)

NewRotatingLogWriter constructs a new RotatingLogWriter.

func (*RotatingLogWriter) Close

func (w *RotatingLogWriter) Close() error

Close closes the logfile.

func (*RotatingLogWriter) Rotate

func (w *RotatingLogWriter) Rotate() error

Rotate closes and re-opens the log file.

func (*RotatingLogWriter) Write

func (w *RotatingLogWriter) Write(p []byte) (int, error)

Write writes a block of data to the logfile.

The input should generally be a single line of JSON data.

type RunFunc added in v0.5.0

type RunFunc func(ctx context.Context)

RunFunc is the callback type for OnRun hooks.

type ShutdownFunc added in v0.5.0

type ShutdownFunc func(ctx context.Context, alreadyTermed bool) error

ShutdownFunc is the callback type for OnShutdown hooks.

type TLSClientConfig

type TLSClientConfig struct {
	Enabled              bool
	SkipVerify           bool
	SkipVerifyServerName bool
	RootCA               string
	ServerName           string
	CommonName           string
	ClientCert           string
	ClientKey            string
}

TLSClientConfig represents the configuration for a client-oriented *tls.Config object.

func (TLSClientConfig) AppendTo

func (cfg TLSClientConfig) AppendTo(out *strings.Builder)

AppendTo appends the string representation to the given Builder.

func (*TLSClientConfig) FromJSON added in v0.4.7

func (cfg *TLSClientConfig) FromJSON(alt *TLSClientConfigJSON) error

FromJSON converts the object's JSON doppelgänger into the object.

func (TLSClientConfig) MakeDialOption added in v0.5.0

func (cfg TLSClientConfig) MakeDialOption(serverName string) (grpc.DialOption, error)

MakeDialOption returns a grpc.DialOption that uses the result of MakeTLS as TLS transport credentials, or returns grpc.WithInsecure() if TLS is disabled.

func (TLSClientConfig) MakeTLS

func (cfg TLSClientConfig) MakeTLS(serverName string) (*tls.Config, error)

MakeTLS constructs the configured *tls.Config, or returns nil if TLS is disabled.

func (TLSClientConfig) MarshalJSON

func (cfg TLSClientConfig) MarshalJSON() ([]byte, error)

MarshalJSON fulfills json.Marshaler.

func (*TLSClientConfig) Parse

func (cfg *TLSClientConfig) Parse(str string) error

Parse parses the string representation.

func (*TLSClientConfig) PostProcess added in v0.4.7

func (cfg *TLSClientConfig) PostProcess() error

PostProcess performs data integrity checks and input post-processing.

func (TLSClientConfig) String

func (cfg TLSClientConfig) String() string

String returns the string representation.

func (TLSClientConfig) ToJSON added in v0.4.7

func (cfg TLSClientConfig) ToJSON() *TLSClientConfigJSON

ToJSON converts the object to its JSON doppelgänger.

func (*TLSClientConfig) UnmarshalJSON

func (cfg *TLSClientConfig) UnmarshalJSON(raw []byte) error

UnmarshalJSON fulfills json.Unmarshaler.

type TLSClientConfigJSON added in v0.4.7

type TLSClientConfigJSON struct {
	SkipVerify           bool   `json:"skipVerify,omitempty"`
	SkipVerifyServerName bool   `json:"skipVerifyServerName,omitempty"`
	RootCA               string `json:"rootCA,omitempty"`
	ServerName           string `json:"serverName,omitempty"`
	CommonName           string `json:"commonName,omitempty"`
	ClientCert           string `json:"clientCert,omitempty"`
	ClientKey            string `json:"clientKey,omitempty"`
}

TLSClientConfigJSON represents the JSON doppelgänger of an TLSClientConfig.

type TLSServerConfig

type TLSServerConfig struct {
	Enabled      bool
	Cert         string
	Key          string
	MutualTLS    bool
	ClientCA     string
	AllowedNames certnames.CertNames
}

TLSServerConfig represents the configuration for a server-oriented *tls.Config object.

func (TLSServerConfig) AppendTo

func (cfg TLSServerConfig) AppendTo(out *strings.Builder)

AppendTo appends the string representation to the given Builder.

func (*TLSServerConfig) FromJSON added in v0.4.7

func (cfg *TLSServerConfig) FromJSON(alt *TLSServerConfigJSON) error

FromJSON converts the object's JSON doppelgänger into the object.

func (TLSServerConfig) MakeGRPCServerOptions added in v0.4.5

func (cfg TLSServerConfig) MakeGRPCServerOptions(opts ...grpc.ServerOption) ([]grpc.ServerOption, error)

MakeGRPCServerOptions constructs the configured gRPC ServerOptions.

func (TLSServerConfig) MakeTLS

func (cfg TLSServerConfig) MakeTLS() (*tls.Config, error)

MakeTLS constructs the configured *tls.Config, or returns nil if TLS is disabled.

func (TLSServerConfig) MarshalJSON

func (cfg TLSServerConfig) MarshalJSON() ([]byte, error)

MarshalJSON fulfills json.Marshaler.

func (*TLSServerConfig) Parse

func (cfg *TLSServerConfig) Parse(str string) error

Parse parses the string representation.

func (*TLSServerConfig) PostProcess added in v0.4.7

func (cfg *TLSServerConfig) PostProcess() error

PostProcess performs data integrity checks and input post-processing.

func (TLSServerConfig) String

func (cfg TLSServerConfig) String() string

String returns the string representation.

func (TLSServerConfig) ToJSON added in v0.4.7

func (cfg TLSServerConfig) ToJSON() *TLSServerConfigJSON

ToJSON converts the object to its JSON doppelgänger.

func (*TLSServerConfig) UnmarshalJSON

func (cfg *TLSServerConfig) UnmarshalJSON(raw []byte) error

UnmarshalJSON fulfills json.Unmarshaler.

type TLSServerConfigJSON added in v0.4.7

type TLSServerConfigJSON struct {
	Cert         string              `json:"cert,omitempty"`
	Key          string              `json:"key,omitempty"`
	MutualTLS    bool                `json:"mTLS,omitempty"`
	ClientCA     string              `json:"clientCA,omitempty"`
	AllowedNames certnames.CertNames `json:"allowedNames,omitempty"`
}

TLSServerConfigJSON represents the JSON doppelgänger of an TLSServerConfig.

type UnknownOptionError added in v0.4.7

type UnknownOptionError struct{}

UnknownOptionError indicates that an unknown option was encountered.

func (UnknownOptionError) Error added in v0.4.7

func (UnknownOptionError) Error() string

Error fulfills the error interface.

type ZKAddAuthError added in v0.4.7

type ZKAddAuthError struct {
	AuthScheme string
	Err        error
}

ZKAddAuthError indicates a problem while authenticating to ZooKeeper.

func (ZKAddAuthError) Error added in v0.4.7

func (err ZKAddAuthError) Error() string

Error fulfills the error interface.

func (ZKAddAuthError) Unwrap added in v0.4.7

func (err ZKAddAuthError) Unwrap() error

Unwrap returns the underlying cause of this error.

type ZKAnnounceConfig

type ZKAnnounceConfig struct {
	ZKConfig
	Path      string
	HostID    string
	NamedPort string
	Format    announcer.Format
}

ZKAnnounceConfig represents the configuration for a *zk.Conn, plus the fields needed to call announcer.NewZK.

func (ZKAnnounceConfig) AddTo

func (cfg ZKAnnounceConfig) AddTo(zkconn *zk.Conn, a *announcer.Announcer) error

AddTo adds this configuration to the provided Announcer.

func (ZKAnnounceConfig) AppendTo

func (cfg ZKAnnounceConfig) AppendTo(out *strings.Builder)

AppendTo appends the string representation to the given Builder.

func (*ZKAnnounceConfig) FromJSON added in v0.4.7

func (cfg *ZKAnnounceConfig) FromJSON(alt *ZKAnnounceConfigJSON) error

FromJSON converts the object's JSON doppelgänger into the object.

func (ZKAnnounceConfig) MarshalJSON

func (cfg ZKAnnounceConfig) MarshalJSON() ([]byte, error)

MarshalJSON fulfills json.Marshaler.

func (*ZKAnnounceConfig) Parse

func (cfg *ZKAnnounceConfig) Parse(str string) error

Parse parses the string representation.

func (*ZKAnnounceConfig) PostProcess added in v0.4.7

func (cfg *ZKAnnounceConfig) PostProcess() error

PostProcess performs data integrity checks and input post-processing.

func (ZKAnnounceConfig) String

func (cfg ZKAnnounceConfig) String() string

String returns the string representation.

func (ZKAnnounceConfig) ToJSON added in v0.4.7

func (cfg ZKAnnounceConfig) ToJSON() *ZKAnnounceConfigJSON

ToJSON converts the object to its JSON doppelgänger.

func (*ZKAnnounceConfig) UnmarshalJSON

func (cfg *ZKAnnounceConfig) UnmarshalJSON(raw []byte) error

UnmarshalJSON fulfills json.Unmarshaler.

type ZKAnnounceConfigJSON added in v0.4.7

type ZKAnnounceConfigJSON struct {
	ZKConfigJSON
	Path      string           `json:"path"`
	HostID    string           `json:"hostID"`
	NamedPort string           `json:"namedPort"`
	Format    announcer.Format `json:"format"`
}

ZKAnnounceConfigJSON represents the JSON doppelgänger of an ZKAnnounceConfig.

type ZKAuthConfig

type ZKAuthConfig struct {
	Enabled  bool
	Scheme   string
	Raw      []byte
	Username string
	Password string
}

ZKAuthConfig represents the configuration for (*zk.Conn).AddAuth.

func (*ZKAuthConfig) FromJSON added in v0.4.7

func (cfg *ZKAuthConfig) FromJSON(alt *ZKAuthConfigJSON) error

FromJSON converts the object's JSON doppelgänger into the object.

func (ZKAuthConfig) MarshalJSON added in v0.4.7

func (cfg ZKAuthConfig) MarshalJSON() ([]byte, error)

MarshalJSON fulfills json.Marshaler.

func (*ZKAuthConfig) PostProcess added in v0.4.7

func (cfg *ZKAuthConfig) PostProcess() error

PostProcess performs data integrity checks and input post-processing.

func (ZKAuthConfig) ToJSON added in v0.4.7

func (cfg ZKAuthConfig) ToJSON() *ZKAuthConfigJSON

ToJSON converts the object to its JSON doppelgänger.

func (*ZKAuthConfig) UnmarshalJSON added in v0.4.7

func (cfg *ZKAuthConfig) UnmarshalJSON(raw []byte) error

UnmarshalJSON fulfills json.Unmarshaler.

type ZKAuthConfigJSON added in v0.4.7

type ZKAuthConfigJSON struct {
	Scheme   string `json:"scheme"`
	Raw      string `json:"raw,omitempty"`
	Username string `json:"username,omitempty"`
	Password string `json:"password,omitempty"`
}

ZKAuthConfigJSON represents the JSON doppelgänger of an ZKAuthConfig.

type ZKConfig

type ZKConfig struct {
	Enabled        bool
	Servers        []string
	SessionTimeout time.Duration
	Auth           ZKAuthConfig
}

ZKConfig represents the configuration for a *zk.Conn.

func (ZKConfig) AppendTo

func (cfg ZKConfig) AppendTo(out *strings.Builder)

AppendTo appends the string representation to the given Builder.

func (ZKConfig) Connect

func (cfg ZKConfig) Connect(ctx context.Context) (*zk.Conn, error)

Connect constructs the configured *zk.Conn and dials the ZooKeeper cluster.

func (*ZKConfig) FromJSON added in v0.4.7

func (cfg *ZKConfig) FromJSON(alt *ZKConfigJSON) error

FromJSON converts the object's JSON doppelgänger into the object.

func (ZKConfig) MarshalJSON

func (cfg ZKConfig) MarshalJSON() ([]byte, error)

MarshalJSON fulfills json.Marshaler.

func (*ZKConfig) Parse

func (cfg *ZKConfig) Parse(str string) error

Parse parses the string representation.

func (*ZKConfig) PostProcess added in v0.4.7

func (cfg *ZKConfig) PostProcess() error

PostProcess performs data integrity checks and input post-processing.

func (ZKConfig) String

func (cfg ZKConfig) String() string

String returns the string representation.

func (ZKConfig) ToJSON added in v0.4.7

func (cfg ZKConfig) ToJSON() *ZKConfigJSON

ToJSON converts the object to its JSON doppelgänger.

func (*ZKConfig) UnmarshalJSON

func (cfg *ZKConfig) UnmarshalJSON(raw []byte) error

UnmarshalJSON fulfills json.Unmarshaler.

type ZKConfigJSON added in v0.4.7

type ZKConfigJSON struct {
	Servers        []string          `json:"servers"`
	SessionTimeout time.Duration     `json:"sessionTimeout,omitempty"`
	Auth           *ZKAuthConfigJSON `json:"auth,omitempty"`
}

ZKConfigJSON represents the JSON doppelgänger of an ZKConfig.

type ZKLoggerBridge

type ZKLoggerBridge struct{}

ZKLoggerBridge is a zk.Logger that forwards to zerolog.

func (ZKLoggerBridge) Printf

func (ZKLoggerBridge) Printf(fmt string, args ...interface{})

Printf fulfills zk.Logger.

type ZapLoggerBridge

type ZapLoggerBridge struct{}

ZapLoggerBridge is a zap.Sink that forwards to zerolog.

func (ZapLoggerBridge) Close

func (ZapLoggerBridge) Close() error

Close fulfills zap.Sink.

func (ZapLoggerBridge) Sync

func (ZapLoggerBridge) Sync() error

Sync fulfills zap.Sink.

func (ZapLoggerBridge) Write

func (ZapLoggerBridge) Write(p []byte) (int, error)

Write fulfills zap.Sink.

Jump to

Keyboard shortcuts

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