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
- 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() error
- func RoxyVersion() string
- func SetAppVersion(version string)
- func SetUniqueFile(path string)
- func UniqueID() (string, error)
- func WithConnContext(ctx context.Context, cc *ConnContext) context.Context
- type ATCAnnounceConfig
- func (aac ATCAnnounceConfig) AddTo(client *atcclient.ATCClient, a *announcer.Announcer) error
- func (aac ATCAnnounceConfig) AppendTo(out *strings.Builder)
- func (aac ATCAnnounceConfig) MarshalJSON() ([]byte, error)
- func (aac *ATCAnnounceConfig) Parse(str string) error
- func (aac ATCAnnounceConfig) String() string
- func (aac *ATCAnnounceConfig) UnmarshalJSON(raw []byte) error
- type ATCClientConfig
- type ConnContext
- type EtcdAnnounceConfig
- func (eac EtcdAnnounceConfig) AddTo(etcd *v3.Client, a *announcer.Announcer) error
- func (eac EtcdAnnounceConfig) AppendTo(out *strings.Builder)
- func (eac EtcdAnnounceConfig) MarshalJSON() ([]byte, error)
- func (eac *EtcdAnnounceConfig) Parse(str string) error
- func (eac EtcdAnnounceConfig) String() string
- func (eac *EtcdAnnounceConfig) UnmarshalJSON(raw []byte) error
- type EtcdConfig
- func (ec EtcdConfig) AppendTo(out *strings.Builder)
- func (ec EtcdConfig) Connect(ctx context.Context) (*v3.Client, error)
- func (ec EtcdConfig) MarshalJSON() ([]byte, error)
- func (ec *EtcdConfig) Parse(str string) error
- func (ec EtcdConfig) String() string
- func (ec *EtcdConfig) UnmarshalJSON(raw []byte) error
- type GRPCClientConfig
- func (gcc GRPCClientConfig) AppendTo(out *strings.Builder)
- func (gcc GRPCClientConfig) Dial(ctx context.Context, opts ...grpc.DialOption) (*grpc.ClientConn, error)
- func (gcc GRPCClientConfig) MarshalJSON() ([]byte, error)
- func (gcc *GRPCClientConfig) Parse(str string) error
- func (gcc GRPCClientConfig) String() string
- func (gcc *GRPCClientConfig) UnmarshalJSON(raw []byte) error
- type HealthServer
- type ListenConfig
- func (lc ListenConfig) AppendTo(out *strings.Builder)
- func (lc ListenConfig) Listen(ctx context.Context) (net.Listener, error)
- func (lc ListenConfig) ListenNoTLS(ctx context.Context) (net.Listener, error)
- func (lc ListenConfig) MarshalJSON() ([]byte, error)
- func (lc *ListenConfig) Parse(str string) error
- func (lc ListenConfig) String() string
- func (lc *ListenConfig) UnmarshalJSON(raw []byte) error
- type MultiServer
- 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) Go(fn func())
- func (m *MultiServer) OnExit(fn func() error)
- func (m *MultiServer) OnReload(fn func() error)
- func (m *MultiServer) OnRun(fn func())
- func (m *MultiServer) OnShutdown(fn func(bool) error)
- func (m *MultiServer) Reload() error
- func (m *MultiServer) Run()
- func (m *MultiServer) Shutdown(graceful bool) error
- type PromLoggerBridge
- type RotatingLogWriter
- type TLSClientConfig
- func (tcc TLSClientConfig) AppendTo(out *strings.Builder)
- func (tcc TLSClientConfig) MakeTLS(serverName string) (*tls.Config, error)
- func (tcc TLSClientConfig) MarshalJSON() ([]byte, error)
- func (tcc *TLSClientConfig) Parse(str string) error
- func (tcc TLSClientConfig) String() string
- func (tcc *TLSClientConfig) UnmarshalJSON(raw []byte) error
- type TLSServerConfig
- func (tsc TLSServerConfig) AppendTo(out *strings.Builder)
- func (tsc TLSServerConfig) MakeGRPCServerOptions(opts ...grpc.ServerOption) ([]grpc.ServerOption, error)
- func (tsc TLSServerConfig) MakeTLS() (*tls.Config, error)
- func (tsc TLSServerConfig) MarshalJSON() ([]byte, error)
- func (tsc *TLSServerConfig) Parse(str string) error
- func (tsc TLSServerConfig) String() string
- func (tsc *TLSServerConfig) UnmarshalJSON(raw []byte) error
- type Target
- type ZKAnnounceConfig
- func (zac ZKAnnounceConfig) AddTo(zkconn *zk.Conn, a *announcer.Announcer) error
- func (zac ZKAnnounceConfig) AppendTo(out *strings.Builder)
- func (zac ZKAnnounceConfig) MarshalJSON() ([]byte, error)
- func (zac *ZKAnnounceConfig) Parse(str string) error
- func (zac ZKAnnounceConfig) String() string
- func (zac *ZKAnnounceConfig) UnmarshalJSON(raw []byte) error
- type ZKAuthConfig
- type ZKConfig
- type ZKLoggerBridge
- type ZapLoggerBridge
Constants ¶
View Source
const ( ConnContextKey = contextKey("roxy.ConnContext") RequestContextKey = contextKey("roxy.RequestContext") )
Variables ¶
This section is empty.
Functions ¶
func AppVersion ¶ added in v0.4.3
func AppVersion() string
AppVersion returns the application version.
func CancelRootContext ¶
func CancelRootContext()
func DoneLogging ¶
func DoneLogging()
func InitContext ¶
func InitContext()
func InitLogging ¶
func InitLogging()
func InitVersion ¶ added in v0.4.3
func InitVersion()
func MakeBaseContextFunc ¶ added in v0.4.4
func MakeConnContextFunc ¶ added in v0.4.4
func NewDummyZapConfig ¶
func RegisterLoggingFlags ¶ added in v0.4.3
func RegisterLoggingFlags()
func RegisterVersionFlag ¶ added in v0.4.3
func RegisterVersionFlag()
func RootContext ¶
func RotateLogs ¶
func RotateLogs() error
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 SetUniqueFile ¶
func SetUniqueFile(path string)
func WithConnContext ¶ added in v0.4.4
func WithConnContext(ctx context.Context, cc *ConnContext) context.Context
Types ¶
type ATCAnnounceConfig ¶
type ATCAnnounceConfig struct {
ATCClientConfig
ServiceName string
Location string
Unique string
NamedPort string
}
func (ATCAnnounceConfig) AppendTo ¶
func (aac ATCAnnounceConfig) AppendTo(out *strings.Builder)
func (ATCAnnounceConfig) MarshalJSON ¶
func (aac ATCAnnounceConfig) MarshalJSON() ([]byte, error)
func (*ATCAnnounceConfig) Parse ¶
func (aac *ATCAnnounceConfig) Parse(str string) error
func (ATCAnnounceConfig) String ¶
func (aac ATCAnnounceConfig) String() string
func (*ATCAnnounceConfig) UnmarshalJSON ¶
func (aac *ATCAnnounceConfig) UnmarshalJSON(raw []byte) error
type ATCClientConfig ¶
type ATCClientConfig struct {
GRPCClientConfig
}
type ConnContext ¶ added in v0.4.4
type ConnContext struct {
Context context.Context
Logger zerolog.Logger
Subsystem string
LocalAddr net.Addr
RemoteAddr net.Addr
}
func GetConnContext ¶ added in v0.4.4
func GetConnContext(ctx context.Context) *ConnContext
type EtcdAnnounceConfig ¶
type EtcdAnnounceConfig struct {
EtcdConfig
Path string
Unique string
NamedPort string
Format announcer.Format
}
func (EtcdAnnounceConfig) AppendTo ¶
func (eac EtcdAnnounceConfig) AppendTo(out *strings.Builder)
func (EtcdAnnounceConfig) MarshalJSON ¶
func (eac EtcdAnnounceConfig) MarshalJSON() ([]byte, error)
func (*EtcdAnnounceConfig) Parse ¶
func (eac *EtcdAnnounceConfig) Parse(str string) error
func (EtcdAnnounceConfig) String ¶
func (eac EtcdAnnounceConfig) String() string
func (*EtcdAnnounceConfig) UnmarshalJSON ¶
func (eac *EtcdAnnounceConfig) UnmarshalJSON(raw []byte) error
type EtcdConfig ¶
type EtcdConfig struct {
Enabled bool
Endpoints []string
TLS TLSClientConfig
Username string
Password string
DialTimeout time.Duration
KeepAlive time.Duration
KeepAliveTimeout time.Duration
}
func (EtcdConfig) AppendTo ¶
func (ec EtcdConfig) AppendTo(out *strings.Builder)
func (EtcdConfig) MarshalJSON ¶
func (ec EtcdConfig) MarshalJSON() ([]byte, error)
func (*EtcdConfig) Parse ¶
func (ec *EtcdConfig) Parse(str string) error
func (EtcdConfig) String ¶
func (ec EtcdConfig) String() string
func (*EtcdConfig) UnmarshalJSON ¶
func (ec *EtcdConfig) UnmarshalJSON(raw []byte) error
type GRPCClientConfig ¶
type GRPCClientConfig struct {
Enabled bool
Target Target
TLS TLSClientConfig
}
func (GRPCClientConfig) AppendTo ¶
func (gcc GRPCClientConfig) AppendTo(out *strings.Builder)
func (GRPCClientConfig) Dial ¶
func (gcc GRPCClientConfig) Dial(ctx context.Context, opts ...grpc.DialOption) (*grpc.ClientConn, error)
func (GRPCClientConfig) MarshalJSON ¶
func (gcc GRPCClientConfig) MarshalJSON() ([]byte, error)
func (*GRPCClientConfig) Parse ¶
func (gcc *GRPCClientConfig) Parse(str string) error
func (GRPCClientConfig) String ¶
func (gcc GRPCClientConfig) String() string
func (*GRPCClientConfig) UnmarshalJSON ¶
func (gcc *GRPCClientConfig) UnmarshalJSON(raw []byte) error
type HealthServer ¶
type HealthServer struct {
grpc_health_v1.UnimplementedHealthServer
// contains filtered or unexported fields
}
func (*HealthServer) Check ¶
func (s *HealthServer) Check(ctx context.Context, req *healthCheckRequest) (*healthCheckResponse, error)
func (*HealthServer) Set ¶
func (s *HealthServer) Set(subsystemName string, healthy bool)
func (*HealthServer) Stop ¶
func (s *HealthServer) Stop()
func (*HealthServer) Watch ¶
func (s *HealthServer) Watch(req *healthCheckRequest, ws grpc_health_v1.Health_WatchServer) error
type ListenConfig ¶
type ListenConfig struct {
Enabled bool
Network string
Address string
TLS TLSServerConfig
}
func (ListenConfig) AppendTo ¶
func (lc ListenConfig) AppendTo(out *strings.Builder)
func (ListenConfig) ListenNoTLS ¶ added in v0.4.5
func (ListenConfig) MarshalJSON ¶
func (lc ListenConfig) MarshalJSON() ([]byte, error)
func (*ListenConfig) Parse ¶
func (lc *ListenConfig) Parse(str string) error
func (ListenConfig) String ¶
func (lc ListenConfig) String() string
func (*ListenConfig) UnmarshalJSON ¶
func (lc *ListenConfig) UnmarshalJSON(raw []byte) error
type MultiServer ¶
type MultiServer struct {
// contains filtered or unexported fields
}
func (*MultiServer) AddGRPCServer ¶
func (*MultiServer) AddHTTPServer ¶
func (*MultiServer) Go ¶
func (m *MultiServer) Go(fn func())
func (*MultiServer) OnExit ¶
func (m *MultiServer) OnExit(fn func() error)
func (*MultiServer) OnReload ¶
func (m *MultiServer) OnReload(fn func() error)
func (*MultiServer) OnRun ¶
func (m *MultiServer) OnRun(fn func())
func (*MultiServer) OnShutdown ¶
func (m *MultiServer) OnShutdown(fn func(bool) error)
func (*MultiServer) Reload ¶
func (m *MultiServer) Reload() error
func (*MultiServer) Run ¶
func (m *MultiServer) Run()
func (*MultiServer) Shutdown ¶
func (m *MultiServer) Shutdown(graceful bool) error
type PromLoggerBridge ¶
type PromLoggerBridge struct{}
func (PromLoggerBridge) Println ¶
func (PromLoggerBridge) Println(v ...interface{})
type RotatingLogWriter ¶
type RotatingLogWriter struct {
// contains filtered or unexported fields
}
func NewRotatingLogWriter ¶
func NewRotatingLogWriter(fileName string) (*RotatingLogWriter, error)
func (*RotatingLogWriter) Close ¶
func (w *RotatingLogWriter) Close() error
func (*RotatingLogWriter) Rotate ¶
func (w *RotatingLogWriter) Rotate() error
type TLSClientConfig ¶
type TLSClientConfig struct {
Enabled bool
SkipVerify bool
SkipVerifyServerName bool
RootCA string
ServerName string
CommonName string
ClientCert string
ClientKey string
}
func (TLSClientConfig) AppendTo ¶
func (tcc TLSClientConfig) AppendTo(out *strings.Builder)
func (TLSClientConfig) MakeTLS ¶
func (tcc TLSClientConfig) MakeTLS(serverName string) (*tls.Config, error)
func (TLSClientConfig) MarshalJSON ¶
func (tcc TLSClientConfig) MarshalJSON() ([]byte, error)
func (*TLSClientConfig) Parse ¶
func (tcc *TLSClientConfig) Parse(str string) error
func (TLSClientConfig) String ¶
func (tcc TLSClientConfig) String() string
func (*TLSClientConfig) UnmarshalJSON ¶
func (tcc *TLSClientConfig) UnmarshalJSON(raw []byte) error
type TLSServerConfig ¶
type TLSServerConfig struct {
Enabled bool
Cert string
Key string
MutualTLS bool
ClientCA string
AllowedNames certnames.CertNames
}
func (TLSServerConfig) AppendTo ¶
func (tsc TLSServerConfig) AppendTo(out *strings.Builder)
func (TLSServerConfig) MakeGRPCServerOptions ¶ added in v0.4.5
func (tsc TLSServerConfig) MakeGRPCServerOptions(opts ...grpc.ServerOption) ([]grpc.ServerOption, error)
func (TLSServerConfig) MarshalJSON ¶
func (tsc TLSServerConfig) MarshalJSON() ([]byte, error)
func (*TLSServerConfig) Parse ¶
func (tsc *TLSServerConfig) Parse(str string) error
func (TLSServerConfig) String ¶
func (tsc TLSServerConfig) String() string
func (*TLSServerConfig) UnmarshalJSON ¶
func (tsc *TLSServerConfig) UnmarshalJSON(raw []byte) error
type Target ¶ added in v0.4.6
type Target = roxyresolver.Target
type ZKAnnounceConfig ¶
type ZKAnnounceConfig struct {
ZKConfig
Path string
Unique string
NamedPort string
Format announcer.Format
}
func (ZKAnnounceConfig) AppendTo ¶
func (zac ZKAnnounceConfig) AppendTo(out *strings.Builder)
func (ZKAnnounceConfig) MarshalJSON ¶
func (zac ZKAnnounceConfig) MarshalJSON() ([]byte, error)
func (*ZKAnnounceConfig) Parse ¶
func (zac *ZKAnnounceConfig) Parse(str string) error
func (ZKAnnounceConfig) String ¶
func (zac ZKAnnounceConfig) String() string
func (*ZKAnnounceConfig) UnmarshalJSON ¶
func (zac *ZKAnnounceConfig) UnmarshalJSON(raw []byte) error
type ZKAuthConfig ¶
type ZKConfig ¶
type ZKConfig struct {
Enabled bool
Servers []string
SessionTimeout time.Duration
Auth ZKAuthConfig
}
func (ZKConfig) MarshalJSON ¶
func (*ZKConfig) UnmarshalJSON ¶
type ZKLoggerBridge ¶
type ZKLoggerBridge struct{}
func (ZKLoggerBridge) Printf ¶
func (ZKLoggerBridge) Printf(fmt string, args ...interface{})
type ZapLoggerBridge ¶
type ZapLoggerBridge struct{}
func (ZapLoggerBridge) Close ¶
func (ZapLoggerBridge) Close() error
func (ZapLoggerBridge) Sync ¶
func (ZapLoggerBridge) Sync() error
Source Files
¶
Click to show internal directories.
Click to hide internal directories.