gophergin

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: 10 Imported by: 0

Documentation

Index

Constants

View Source
const Author = "github.com/lordofthemind"

Author of the gophergin package

View Source
const Description = "" /* 155-byte string literal not displayed */

Description of the gophergin package

View Source
const Version = "1.0.1"

Version of the gophergin package

Variables

This section is empty.

Functions

This section is empty.

Types

type GinServer

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

GinServer is the modular implementation of the Server interface. It wraps around Gin's HTTP server and provides modular setup and shutdown.

func (*GinServer) GetRouter

func (gs *GinServer) GetRouter() *gin.Engine

GetRouter returns the gin.Engine instance.

Returns: - *gin.Engine: The underlying Gin engine for the server.

func (*GinServer) GracefulShutdown

func (gs *GinServer) GracefulShutdown()

GracefulShutdown gracefully shuts down the server when interrupted.

This method handles system interrupts (e.g., Ctrl+C) and shuts down the server gracefully, allowing for ongoing requests to finish within a 5-second timeout.

func (*GinServer) Start

func (gs *GinServer) Start() error

Start starts the Gin server, either with or without TLS.

Returns: - error: Any error encountered while starting the server.

type Server

type Server interface {
	Start() error
	GracefulShutdown()
	GetRouter() *gin.Engine
}

Server interface defines the behavior of a Gin server.

Methods: - Start: Starts the server (optionally with TLS). - GracefulShutdown: Gracefully shuts down the server when interrupted. - GetRouter: Returns the underlying gin.Engine for additional route setup.

func NewGinServer

func NewGinServer(setup ServerSetup, config ServerConfig) Server

NewGinServer creates a new GinServer instance with injected dependencies.

Parameters: - setup: A ServerSetup implementation for initializing the server. - config: The ServerConfig structure for server configuration.

Returns: - Server: A configured Gin server 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 for setting up the server.

Fields: - Port: Port number to run the server on. - UseTLS: Enable TLS (HTTPS) if true. - 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: Enable CORS (Cross-Origin Resource Sharing) if true. - CORSConfig: Configures allowed origins, headers, and methods for CORS.

type ServerSetup

type ServerSetup interface {
	SetUpRouter(config ServerConfig) *gin.Engine
	SetUpTLS(config ServerConfig) (*tls.Config, error)
	SetUpCORS(router *gin.Engine, config ServerConfig)
}

ServerSetup defines the behavior for setting up a Gin server.

Methods: - SetUpRouter: Configures and returns a new Gin engine. - SetUpTLS: Configures TLS settings if required (returns a tls.Config instance). - SetUpCORS: Applies CORS middleware to the Gin engine if enabled.

type ServerSetupImpl

type ServerSetupImpl struct{}

ServerSetupImpl is the concrete implementation of ServerSetup.

func (*ServerSetupImpl) SetUpCORS

func (s *ServerSetupImpl) SetUpCORS(router *gin.Engine, config ServerConfig)

SetUpCORS configures and applies CORS middleware if enabled.

Parameters: - router: The Gin engine to apply the middleware to. - config: The server configuration that contains CORS settings.

func (*ServerSetupImpl) SetUpRouter

func (s *ServerSetupImpl) SetUpRouter(config ServerConfig) *gin.Engine

SetUpRouter sets up a Gin server.

Parameters: - config: The server configuration.

Returns: - *gin.Engine: A configured Gin engine.

func (*ServerSetupImpl) SetUpTLS

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

SetUpTLS configures the server for TLS (HTTPS) if enabled.

Parameters: - config: The server configuration containing TLS settings.

Returns: - *tls.Config: TLS configuration if enabled, or nil if not. - error: An error if TLS certificates cannot be loaded.

Jump to

Keyboard shortcuts

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