server

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ChainMiddlewares added in v1.3.1

func ChainMiddlewares(finalHandler http.Handler, middlewares ...func(http.Handler) http.Handler) http.Handler

ChainMiddlewares chains multiple HTTP middlewares in the correct order. Takes a final handler and variadic middlewares, applying them from last to first. Returns the final wrapped http.Handler with all middlewares applied. This function maintains backward compatibility with existing projects.

func DetermineEnvironment added in v1.3.8

func DetermineEnvironment(sslKeyPath, sslCertPath string) string

determineEnvironment determines the server environment based on SSL file availability. Returns "Production" if both SSL files exist and are valid, otherwise "Development". Performs comprehensive validation of SSL files in production mode.

func StartServer

func StartServer(handler http.Handler) error

StartServer starts an HTTP or HTTPS server with graceful shutdown support. Uses the provided handler and configuration, supporting TLS for Production mode. This function maintains backward compatibility while adding health endpoint at /health and optional connection limiting.

Parameters:

  • handler: The HTTP handler to serve requests (router, mux, etc.)

Returns:

  • error: Any error encountered during server startup, operation, or shutdown

Example:

err := server.StartServer(router)
if err != nil {
    log.Fatal("Server failed: " + err.Error())
}

Types

type ServerConfig added in v1.3.7

type ServerConfig struct {
	Port            string        // Port specifies the TCP port for the server to listen on
	SSLKeyPath      string        // SSLKeyPath specifies the file path to the SSL private key
	SSLCertPath     string        // SSLCertPath specifies the file path to the SSL certificate
	ReadTimeout     time.Duration // ReadTimeout is the maximum duration for reading the entire request
	WriteTimeout    time.Duration // WriteTimeout is the maximum duration for writing the response
	IdleTimeout     time.Duration // IdleTimeout is the maximum duration for idle connections
	ShutdownTimeout time.Duration // ShutdownTimeout is the duration for graceful shutdown
	MaxHeaderBytes  int           // MaxHeaderBytes limits the maximum size of request headers
	MaxConnections  int           // MaxConnections limits concurrent connections (0 = no limit)
}

ServerConfig holds configuration parameters for the HTTP server. This struct centralizes all server settings for better maintainability.

func LoadConfig added in v1.3.7

func LoadConfig() ServerConfig

LoadConfig loads server configuration from environment variables with defaults. Returns a ServerConfig struct with validated and default values.

Jump to

Keyboard shortcuts

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