mainutil

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: May 14, 2021 License: Apache-2.0 Imports: 44 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    = 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 MakeBaseContextFunc() func(net.Listener) context.Context

func MakeConnContextFunc added in v0.4.4

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

func NewDummyZapConfig

func NewDummyZapConfig() *zap.Config

func RegisterLoggingFlags added in v0.4.3

func RegisterLoggingFlags()

func RegisterVersionFlag added in v0.4.3

func RegisterVersionFlag()

func RootContext

func RootContext() context.Context

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 UniqueID

func UniqueID() (string, error)

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) AddTo

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
}

func (ATCClientConfig) NewClient

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

type ConnContext added in v0.4.4

type ConnContext struct {
	Context    context.Context
	Logger     zerolog.Logger
	Proto      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) AddTo

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

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) Connect

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

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  RoxyTarget
	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) Listen

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

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 (m *MultiServer) AddGRPCServer(name string, server *grpc.Server, listen net.Listener)

func (*MultiServer) AddHTTPServer

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

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

func (*RotatingLogWriter) Write

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

type RoxyTarget

type RoxyTarget = roxyresolver.RoxyTarget

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
	CommonNames []string
}

func (TLSServerConfig) AppendTo

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

func (TLSServerConfig) MakeTLS

func (tsc TLSServerConfig) MakeTLS() (*tls.Config, 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 ZKAnnounceConfig

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

func (ZKAnnounceConfig) AddTo

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

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 ZKAuthConfig struct {
	Enabled  bool
	Scheme   string
	Raw      []byte
	Username string
	Password string
}

type ZKConfig

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

func (ZKConfig) AppendTo

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

func (ZKConfig) Connect

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

func (ZKConfig) MarshalJSON

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

func (*ZKConfig) Parse

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

func (ZKConfig) String

func (zc ZKConfig) String() string

func (*ZKConfig) UnmarshalJSON

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

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

func (ZapLoggerBridge) Write

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

Jump to

Keyboard shortcuts

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