engine

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Checker

type Checker interface {
	Check(ctx context.Context) error
	GetName() string
}

type Closer

type Closer interface {
	GetName() string

	Close(ctx context.Context) error
}

func NewDefaultCloser

func NewDefaultCloser(name string, close func(ctx context.Context) error) Closer

type DebugServer

type DebugServer struct {
	PORT string `json:"port" envconfig:"PORT" default:":8084"`
	// contains filtered or unexported fields
}

func NewDebugServer

func NewDebugServer(port string) *DebugServer

NewDebugServer create new debug server

port is debug port use value with `:` for example: :8084

func (*DebugServer) AddChecker

func (d *DebugServer) AddChecker(checker Checker)

func (*DebugServer) AddCheckers

func (d *DebugServer) AddCheckers(checkers []Checker)

AddCheckers for check your server is live

func (*DebugServer) LiveProbeHandler added in v0.2.0

func (d *DebugServer) LiveProbeHandler(w http.ResponseWriter, _ *http.Request)

LiveProbeHandler is probe checker for k8s liveness probe

func (*DebugServer) ReadinessProbeHandler added in v0.2.0

func (d *DebugServer) ReadinessProbeHandler(w http.ResponseWriter, req *http.Request)

ReadinessProbeHandler is probe checker for k8s readiness probe

It will check all checkersGroup and return 200 if all checkersGroup is ok or 500 if one of them is not ok

response will be json with all checkersGroup and their status

func (*DebugServer) RunDebug

func (d *DebugServer) RunDebug() error

func (*DebugServer) SetReady

func (d *DebugServer) SetReady(ready bool)

SetReady set server ready

warning use this method only when you sure that server is ready

func (*DebugServer) ShutdownDebug

func (d *DebugServer) ShutdownDebug(ctx context.Context) error

func (*DebugServer) StartupProbeHandler added in v0.2.0

func (d *DebugServer) StartupProbeHandler(w http.ResponseWriter, _ *http.Request)

StartupProbeHandler is probe checker for k8s startup probe ready or not ready used only for start

type DefaultChecker

type DefaultChecker struct {
	CheckFunc func(ctx context.Context) error `json:"check"`
	NameCheck string                          `json:"name"`
}

DefaultChecker is a default implementation of Checker if you want simple checker without implementation Checker interface tou can call this function and receive Checker interface

func NewDefaultChecker

func NewDefaultChecker(name string, checkFunc func(ctx context.Context) error) *DefaultChecker

func (*DefaultChecker) Check

func (c *DefaultChecker) Check(ctx context.Context) error

func (*DefaultChecker) GetName added in v0.2.0

func (c *DefaultChecker) GetName() string

type DefaultCloser

type DefaultCloser struct {
	Name      string                          `json:"name"`
	CloseFunc func(ctx context.Context) error `json:"close"`
}

DefaultCloser is a default implementation of Closer if you want simple checker without implementation Closer interface tou can call this function and receive Closer interface

func (*DefaultCloser) Close

func (d *DefaultCloser) Close(ctx context.Context) error

func (*DefaultCloser) GetName

func (d *DefaultCloser) GetName() string

type ErrorCloser added in v0.2.0

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

func (*ErrorCloser) Error added in v0.2.0

func (e *ErrorCloser) Error() string

type Server

type Server struct {
	*DebugServer
	// contains filtered or unexported fields
}

Server is app engine with debug server

Use AddCloser to add closer objects for shutdown your application gracefully(for more information see AddCloser)

Use AddActor to add actor control you background task(for more information see AddActor)

Use AddChecker to add checker for live probe(for more information see AddChecker)

You can change config engine use ENV variables DEBUG_PORT and SHUTDOWN_TIMEOUT(for example 30s)

func NewServer

func NewServer(opt ...ServerOpt) *Server

NewServer create new server

You can change config engine use ENV variables DEBUG_PORT and SHUTDOWN_TIMEOUT(for example 30s) or use With function

func (*Server) AddActor

func (s *Server) AddActor(execute func() error, interrupt func(err error))

AddActor add actor control you background task

you have executed function and done function(interrupt function) interrupt function handle the error execute function is called when server is ready

func (*Server) AddCloser

func (s *Server) AddCloser(closer Closer)

AddCloser add closer object for shutdown your application gracefully you need to handle the context and call wg.Done() when done

func (*Server) AddClosers

func (s *Server) AddClosers(closers []Closer)

func (*Server) GetCTX

func (s *Server) GetCTX() context.Context

GetCTX return context of your engine

func (*Server) Run

func (s *Server) Run() error

Run start your server

func (*Server) Shutdown

func (s *Server) Shutdown() error

Shutdown server

Timeout is duration for graceful shutdown If all goroutines are finished, server will be shutdown or timeout will be reached, server will be shutdown force

type ServerOpt

type ServerOpt func(*Server)

func WithDebugPort

func WithDebugPort(port string) ServerOpt

WithDebugPort set debug port use value with `:` for example: :8084

func WithDisableBanner

func WithDisableBanner() ServerOpt

WithDisableBanner disable witcher Banner

func WithGRPCServer added in v0.0.5

func WithGRPCServer(grpcServer *grpc.Server, port string, shutdownTimeout time.Duration) ServerOpt

func WithShutdownTimeout

func WithShutdownTimeout(timeout time.Duration) ServerOpt

WithShutdownTimeout set shutdown timeout

is duration for graceful shutdown

Jump to

Keyboard shortcuts

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