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
- Variables
- func AppVersion() string
- func CancelRootContext()
- func DoneLogging()
- func InitContext()
- func InitLogging()
- func InitVersion()
- func MakeBaseContextFunc() func(net.Listener) context.Context
- func MakeConnContextFunc(name string) func(context.Context, net.Conn) context.Context
- func NewDummyZapConfig() *zap.Config
- func RegisterLoggingFlags()
- func RegisterVersionFlag()
- func RootContext() context.Context
- func RotateLogs(ctx context.Context) error
- func RoxyVersion() string
- func SetAppVersion(version string)
- func WithConnContext(ctx context.Context, cc *ConnContext) context.Context
- type ATCAnnounceConfig
- func (cfg ATCAnnounceConfig) AddTo(client *atcclient.ATCClient, a *announcer.Announcer) error
- func (cfg ATCAnnounceConfig) AppendTo(out *strings.Builder)
- func (cfg *ATCAnnounceConfig) FromJSON(alt *ATCAnnounceConfigJSON) error
- func (cfg ATCAnnounceConfig) MarshalJSON() ([]byte, error)
- func (cfg *ATCAnnounceConfig) Parse(str string) error
- func (cfg *ATCAnnounceConfig) PostProcess() error
- func (cfg ATCAnnounceConfig) String() string
- func (cfg ATCAnnounceConfig) ToJSON() *ATCAnnounceConfigJSON
- func (cfg *ATCAnnounceConfig) UnmarshalJSON(raw []byte) error
- type ATCAnnounceConfigJSON
- type ATCClientConfig
- func (cfg ATCClientConfig) AppendTo(out *strings.Builder)
- func (cfg *ATCClientConfig) FromJSON(alt *ATCClientConfigJSON) error
- func (cfg ATCClientConfig) MarshalJSON() ([]byte, error)
- func (cfg ATCClientConfig) NewClient(ctx context.Context) (*atcclient.ATCClient, error)
- func (cfg *ATCClientConfig) Parse(str string) error
- func (cfg *ATCClientConfig) PostProcess() error
- func (cfg ATCClientConfig) String() string
- func (cfg ATCClientConfig) ToJSON() *ATCClientConfigJSON
- func (cfg *ATCClientConfig) UnmarshalJSON(raw []byte) error
- type ATCClientConfigJSON
- type CertKeyError
- type CertPoolError
- type ConnContext
- type EtcdAnnounceConfig
- func (cfg EtcdAnnounceConfig) AddTo(etcd *v3.Client, a *announcer.Announcer) error
- func (cfg EtcdAnnounceConfig) AppendTo(out *strings.Builder)
- func (cfg *EtcdAnnounceConfig) FromJSON(alt *EtcdAnnounceConfigJSON) error
- func (cfg EtcdAnnounceConfig) MarshalJSON() ([]byte, error)
- func (cfg *EtcdAnnounceConfig) Parse(str string) error
- func (cfg *EtcdAnnounceConfig) PostProcess() error
- func (cfg EtcdAnnounceConfig) String() string
- func (cfg EtcdAnnounceConfig) ToJSON() *EtcdAnnounceConfigJSON
- func (cfg *EtcdAnnounceConfig) UnmarshalJSON(raw []byte) error
- type EtcdAnnounceConfigJSON
- type EtcdConfig
- func (cfg EtcdConfig) AppendTo(out *strings.Builder)
- func (cfg EtcdConfig) Connect(ctx context.Context) (*v3.Client, error)
- func (cfg *EtcdConfig) FromJSON(alt *EtcdConfigJSON) error
- func (cfg EtcdConfig) MarshalJSON() ([]byte, error)
- func (cfg *EtcdConfig) Parse(str string) error
- func (cfg *EtcdConfig) PostProcess() error
- func (cfg EtcdConfig) String() string
- func (cfg EtcdConfig) ToJSON() *EtcdConfigJSON
- func (cfg *EtcdConfig) UnmarshalJSON(raw []byte) error
- type EtcdConfigJSON
- type ExitFunc
- type GRPCClientConfig
- func (cfg GRPCClientConfig) AppendTo(out *strings.Builder)
- func (cfg GRPCClientConfig) Dial(ctx context.Context, opts ...grpc.DialOption) (*grpc.ClientConn, error)
- func (cfg *GRPCClientConfig) FromJSON(alt *GRPCClientConfigJSON) error
- func (cfg GRPCClientConfig) MarshalJSON() ([]byte, error)
- func (cfg *GRPCClientConfig) Parse(str string) error
- func (cfg *GRPCClientConfig) PostProcess() error
- func (cfg GRPCClientConfig) String() string
- func (cfg GRPCClientConfig) ToJSON() *GRPCClientConfigJSON
- func (cfg *GRPCClientConfig) UnmarshalJSON(raw []byte) error
- type GRPCClientConfigJSON
- type HealthWatchFunc
- type HealthWatchID
- type ListenConfig
- func (cfg ListenConfig) AppendTo(out *strings.Builder)
- func (cfg *ListenConfig) FromJSON(alt *ListenConfigJSON) error
- func (cfg ListenConfig) Listen(ctx context.Context) (net.Listener, error)
- func (cfg ListenConfig) ListenNoTLS(ctx context.Context) (net.Listener, error)
- func (cfg ListenConfig) MarshalJSON() ([]byte, error)
- func (cfg *ListenConfig) Parse(str string) error
- func (cfg *ListenConfig) PostProcess() error
- func (cfg ListenConfig) String() string
- func (cfg ListenConfig) ToJSON() *ListenConfigJSON
- func (cfg *ListenConfig) UnmarshalJSON(raw []byte) error
- type ListenConfigJSON
- type MissingOptionValueError
- type MultiServer
- func (m *MultiServer) AddAnnouncer(ann *announcer.Announcer, r *membership.Roxy)
- func (m *MultiServer) AddGRPCServer(name string, server *grpc.Server, listen net.Listener)
- func (m *MultiServer) AddHTTPServer(name string, server *http.Server, listen net.Listener)
- func (m *MultiServer) CancelWatchHealth(id HealthWatchID)
- func (m *MultiServer) Done() <-chan struct{}
- func (m *MultiServer) GetHealth(subsystemName string) (isHealthy bool, found bool)
- func (m *MultiServer) Go(ctx context.Context, fn RunFunc)
- func (m *MultiServer) HealthServer() grpc_health_v1.HealthServer
- func (m *MultiServer) OnExit(fn ExitFunc)
- func (m *MultiServer) OnPreRun(fn PreRunFunc)
- func (m *MultiServer) OnPreShutdown(fn PreShutdownFunc)
- func (m *MultiServer) OnReload(fn ReloadFunc)
- func (m *MultiServer) OnRun(fn RunFunc)
- func (m *MultiServer) OnShutdown(fn ShutdownFunc)
- func (m *MultiServer) Reload(ctx context.Context) error
- func (m *MultiServer) Run(ctx context.Context) error
- func (m *MultiServer) SetHealth(subsystemName string, isHealthy bool)
- func (m *MultiServer) Shutdown(ctx context.Context, graceful bool) error
- func (m *MultiServer) WatchHealth(fn HealthWatchFunc) HealthWatchID
- type OptionError
- type PreRunFunc
- type PreShutdownFunc
- type PromLoggerBridge
- type ReloadFunc
- type RotatingLogWriter
- type RunFunc
- type ShutdownFunc
- type TLSClientConfig
- func (cfg TLSClientConfig) AppendTo(out *strings.Builder)
- func (cfg *TLSClientConfig) FromJSON(alt *TLSClientConfigJSON) error
- func (cfg TLSClientConfig) MakeDialOption(serverName string) (grpc.DialOption, error)
- func (cfg TLSClientConfig) MakeTLS(serverName string) (*tls.Config, error)
- func (cfg TLSClientConfig) MarshalJSON() ([]byte, error)
- func (cfg *TLSClientConfig) Parse(str string) error
- func (cfg *TLSClientConfig) PostProcess() error
- func (cfg TLSClientConfig) String() string
- func (cfg TLSClientConfig) ToJSON() *TLSClientConfigJSON
- func (cfg *TLSClientConfig) UnmarshalJSON(raw []byte) error
- type TLSClientConfigJSON
- type TLSServerConfig
- func (cfg TLSServerConfig) AppendTo(out *strings.Builder)
- func (cfg *TLSServerConfig) FromJSON(alt *TLSServerConfigJSON) error
- func (cfg TLSServerConfig) MakeGRPCServerOptions(opts ...grpc.ServerOption) ([]grpc.ServerOption, error)
- func (cfg TLSServerConfig) MakeTLS() (*tls.Config, error)
- func (cfg TLSServerConfig) MarshalJSON() ([]byte, error)
- func (cfg *TLSServerConfig) Parse(str string) error
- func (cfg *TLSServerConfig) PostProcess() error
- func (cfg TLSServerConfig) String() string
- func (cfg TLSServerConfig) ToJSON() *TLSServerConfigJSON
- func (cfg *TLSServerConfig) UnmarshalJSON(raw []byte) error
- type TLSServerConfigJSON
- type UnknownOptionError
- type ZKAddAuthError
- type ZKAnnounceConfig
- func (cfg ZKAnnounceConfig) AddTo(zkconn *zk.Conn, a *announcer.Announcer) error
- func (cfg ZKAnnounceConfig) AppendTo(out *strings.Builder)
- func (cfg *ZKAnnounceConfig) FromJSON(alt *ZKAnnounceConfigJSON) error
- func (cfg ZKAnnounceConfig) MarshalJSON() ([]byte, error)
- func (cfg *ZKAnnounceConfig) Parse(str string) error
- func (cfg *ZKAnnounceConfig) PostProcess() error
- func (cfg ZKAnnounceConfig) String() string
- func (cfg ZKAnnounceConfig) ToJSON() *ZKAnnounceConfigJSON
- func (cfg *ZKAnnounceConfig) UnmarshalJSON(raw []byte) error
- type ZKAnnounceConfigJSON
- type ZKAuthConfig
- type ZKAuthConfigJSON
- type ZKConfig
- func (cfg ZKConfig) AppendTo(out *strings.Builder)
- func (cfg ZKConfig) Connect(ctx context.Context) (*zk.Conn, error)
- func (cfg *ZKConfig) FromJSON(alt *ZKConfigJSON) error
- func (cfg ZKConfig) MarshalJSON() ([]byte, error)
- func (cfg *ZKConfig) Parse(str string) error
- func (cfg *ZKConfig) PostProcess() error
- func (cfg ZKConfig) String() string
- func (cfg ZKConfig) ToJSON() *ZKConfigJSON
- func (cfg *ZKConfig) UnmarshalJSON(raw []byte) error
- type ZKConfigJSON
- type ZKLoggerBridge
- type ZapLoggerBridge
Constants ¶
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 ¶
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 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 MakeBaseContextFunc ¶ added in v0.4.4
MakeBaseContextFunc returns a "net/http".(*Server).BaseContextFunc that returns the root context.
func MakeConnContextFunc ¶ added in v0.4.4
MakeConnContextFunc returns a "net/http".(*Server).ConnContextFunc that prepares a *ConnContext and calls WithConnContext.
func NewDummyZapConfig ¶
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 RotateLogs ¶
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) 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
func (cfg ATCAnnounceConfig) ToJSON() *ATCAnnounceConfigJSON
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 ¶
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
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
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) 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
func (cfg EtcdAnnounceConfig) ToJSON() *EtcdAnnounceConfigJSON
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 ¶
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 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
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) ListenNoTLS ¶ added in v0.4.5
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
func (MissingOptionValueError) Error() string
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 ¶
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 ¶
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
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
PreRunFunc is the callback type for OnPreRun hooks.
type PreShutdownFunc ¶ added in v0.5.0
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
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.
type ShutdownFunc ¶ added in v0.5.0
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
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) 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 ¶
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) Connect ¶
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 ¶
MarshalJSON fulfills json.Marshaler.
func (*ZKConfig) PostProcess ¶ added in v0.4.7
PostProcess performs data integrity checks and input post-processing.
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 ¶
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.