gopherfiber

package module
v0.0.0-...-b54bd16 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FiberServer

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

FiberServer wraps the Fiber app and provides modular setup and graceful shutdown.

Fields: - app: The Fiber app instance used for routing and middleware. - tlsConfig: Optional TLS configuration for serving HTTPS. - serverSetup: The ServerSetup instance used to configure the server. - config: The ServerConfig structure containing the server's configuration.

func (*FiberServer) GetRouter

func (fs *FiberServer) GetRouter() *fiber.App

GetRouter returns the underlying Fiber app instance.

Returns: - *fiber.App: The Fiber app used for routing and middleware.

func (*FiberServer) GracefulShutdown

func (fs *FiberServer) GracefulShutdown()

GracefulShutdown shuts down the server gracefully on receiving an interrupt signal.

This method ensures ongoing requests are completed before shutting down.

func (*FiberServer) Start

func (fs *FiberServer) Start() error

Start starts the Fiber server with or without TLS, depending on the configuration.

Returns: - error: Any error encountered during server startup.

type Server

type Server interface {
	Start() error
	GracefulShutdown()
	GetRouter() *fiber.App
}

Server interface defines the behavior of a Fiber server.

Methods: - Start: Starts the server (optionally with TLS). - GracefulShutdown: Gracefully shuts down the server on interrupt. - GetRouter: Returns the underlying fiber.App instance for adding routes.

func NewFiberServer

func NewFiberServer(setup ServerSetup, config ServerConfig) Server

NewFiberServer creates a new FiberServer instance with the provided configuration.

Parameters: - setup: The ServerSetup implementation to configure the server. - config: The ServerConfig structure containing configuration details.

Returns: - Server: A configured Fiber server instance ready to start.

type ServerConfig

type ServerConfig struct {
	Port        int
	UseTLS      bool
	TLSCertFile string
	TLSKeyFile  string
	UseCORS     bool
	CORSConfig  cors.Config
}

ServerConfig holds the configuration options for the server.

Fields: - Port: The port number where the server will listen for incoming requests. - UseTLS: Set to true if you want to enable HTTPS using TLS. - TLSCertFile: Path to the TLS certificate file (required if UseTLS is true). - TLSKeyFile: Path to the TLS key file (required if UseTLS is true). - UseCORS: Set to true to enable Cross-Origin Resource Sharing (CORS). - CORSConfig: CORS configuration to allow specific origins and methods.

type ServerSetup

type ServerSetup interface {
	SetUpRouter(config ServerConfig) *fiber.App
	SetUpTLS(config ServerConfig) (*tls.Config, error)
	SetUpCORS(app *fiber.App, config ServerConfig)
}

ServerSetup interface defines the setup methods for configuring a Fiber server.

Methods: - SetUpRouter: Sets up the Fiber app without static files or templates. - SetUpTLS: Configures TLS settings for HTTPS if enabled. - SetUpCORS: Applies CORS middleware to the app if enabled.

type ServerSetupImpl

type ServerSetupImpl struct{}

ServerSetupImpl is the concrete implementation of the ServerSetup interface.

func (*ServerSetupImpl) SetUpCORS

func (s *ServerSetupImpl) SetUpCORS(app *fiber.App, config ServerConfig)

SetUpCORS configures and applies CORS middleware to the app if enabled.

Parameters: - app: The Fiber app to apply CORS middleware to. - config: The ServerConfig containing CORS configuration options.

func (*ServerSetupImpl) SetUpRouter

func (s *ServerSetupImpl) SetUpRouter(config ServerConfig) *fiber.App

SetUpRouter sets up a Fiber app without static file serving or template rendering.

Parameters: - config: The ServerConfig structure.

Returns: - *fiber.App: The Fiber app instance.

func (*ServerSetupImpl) SetUpTLS

func (s *ServerSetupImpl) SetUpTLS(config ServerConfig) (*tls.Config, error)

SetUpTLS configures TLS (HTTPS) settings if enabled.

Parameters: - config: The ServerConfig containing the paths to the TLS certificate and key files.

Returns: - *tls.Config: The TLS configuration if UseTLS is true, or nil if not. - error: An error if the certificate or key cannot be loaded.

Jump to

Keyboard shortcuts

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