Documentation
¶
Overview ¶
Package httpgin provides a Gin-based implementation of the Things-Kit HTTP server interface. This is the default HTTP implementation for Things-Kit, but users can provide their own implementations using different frameworks (Chi, Echo, stdlib, etc.).
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Module = fx.Module("httpgin", fx.Provide( NewConfig, NewGinServer, fx.Annotate( func(s *GinServer) httpmodule.Server { return s }, fx.As(new(httpmodule.Server)), ), ), fx.Invoke(RunHttpServer), )
Module provides the Gin-based HTTP server module to the application. This module implements the http.Server interface using the Gin framework.
Functions ¶
func AsGinHandler ¶
AsGinHandler is a generic helper to provide a Gin HTTP handler to the Fx graph. The constructor should return a type that implements the GinHandler interface.
Example:
type MyHandler struct {
logger log.Logger
}
func NewMyHandler(logger log.Logger) *MyHandler {
return &MyHandler{logger: logger}
}
func (h *MyHandler) RegisterRoutes(engine *gin.Engine) {
engine.GET("/hello", func(c *gin.Context) {
c.JSON(200, gin.H{"message": "Hello World"})
})
}
// In main.go:
httpgin.AsGinHandler(NewMyHandler)
func RunHttpServer ¶
func RunHttpServer(p HttpServerParams, server *GinServer)
RunHttpServer starts the HTTP server with registered handlers. This is invoked by Fx during application startup.
Types ¶
type Config ¶
type Config struct {
httpmodule.Config `mapstructure:",squash"`
Mode string `mapstructure:"mode"` // debug, release, test
}
Config holds the Gin-specific HTTP server configuration. It embeds the common http.Config and adds Gin-specific options.
type GinHandler ¶
GinHandler is a Gin-specific implementation of http.Handler. Handlers that implement this interface can be registered with AsGinHandler.
type GinServer ¶
type GinServer struct {
// contains filtered or unexported fields
}
GinServer implements the http.Server interface using Gin.
func NewGinServer ¶
NewGinServer creates a new Gin server instance.
func (*GinServer) Engine ¶
Engine returns the underlying Gin engine. This is useful for registering middleware or customizing the engine.
type HttpServerParams ¶
type HttpServerParams struct {
fx.In
Lifecycle fx.Lifecycle
Logger log.Logger
Config *Config
Handlers []GinHandler `group:"http.handlers"`
}
HttpServerParams contains all dependencies needed to run the HTTP server.