server

package
v0.4.6 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2025 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultHTTPPort     = 80
	DefaultHTTPSPort    = 443
	DefaultAdminPort    = 8080
	ReadTimeout         = 15 * time.Second
	WriteTimeout        = 15 * time.Second
	IdleTimeout         = 60 * time.Second
	TLSMinVersion       = tls.VersionTLS12
	ShutdownGracePeriod = 30 * time.Second
	DefaultLogName      = "service_default"
	DefaultPluginPath   = "./plugins"
	PluginLoadTime      = 10 * time.Second
)

default configurations

Variables

This section is empty.

Functions

This section is empty.

Types

type HostHandler added in v0.4.6

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

HostHandler represents a pre-configured handler for a specific host. By storing both logger and handler, we avoid context lookups during request processing.

type Server

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

Server encapsulates all the components and configurations required to run the Terraster server. Manages HTTP/HTTPS servers, health checkers, admin APIs, TLS configurations, and service pools.

func NewServer

func NewServer(
	srvCtx context.Context,
	errChan chan<- error,
	cfg *config.Terraster,
	apiCfg *config.APIConfig,
	authSrvc *auth_service.AuthService,
	zLog *zap.Logger,
	logManager *logger.LoggerManager,
) (*Server, error)

NewServer is a entrypoint for load balancer setup. It handles health checkers for each service, initializes the admin API, setup service log (if any) and prepares the server for startup. Will exit with error message if anything goes wrong

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

Shutdown gracefully shuts down all running servers, including the admin server and all service servers. Also stops all health checkers and waits for all goroutines to finish within the provided context's deadline.

func (*Server) Start

func (s *Server) Start() error

Start initializes and starts all configured HTTP/HTTPS servers along with the admin server. It sets up TLS configurations, loads certificates, and begins listening for incoming requests. Also starts all health checkers in separate goroutines. Returns an error if any server fails to start.

type VirtualServiceHandler added in v0.4.6

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

VirtualServiceHandler manages multiple service handlers on the same port. This is the core component that enables efficient handling of multiple services sharing the same port while maintaining separate configurations.

func NewVirtualServiceHandler added in v0.4.6

func NewVirtualServiceHandler() *VirtualServiceHandler

NewVirtualServiceHandler creates a new handler manager. This is called once per port during server initialization.

func (*VirtualServiceHandler) AddService added in v0.4.6

func (mh *VirtualServiceHandler) AddService(s *Server, svc *service.ServiceInfo)

AddService configures and stores a complete handler chain for a service. This is called during service registration, NOT during request processing. The key performance aspect is that this build the entire middleware chain once during initialization, rather than per-request.

func (*VirtualServiceHandler) ServeHTTP added in v0.4.6

func (mh *VirtualServiceHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP is the entry point for all requests.

Jump to

Keyboard shortcuts

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