gin
HTTP server module for MinStack, built on Gin.
Installation
sh
go get github.com/go-minstack/ginUsage
go
import (
"github.com/go-minstack/core"
mgin "github.com/go-minstack/gin"
)
func registerRoutes(r *gin.Engine) {
r.GET("/hello", func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"message": "Hello!"})
})
}
func main() {
app := core.New(mgin.Module())
app.Invoke(registerRoutes)
app.Run()
}Import alias
The package name is gin, which conflicts with github.com/gin-gonic/gin. Use mgin as an alias.
API
gin.Module() fx.Option
Registers a *gin.Engine into the DI container. All Gin debug output and HTTP request logs are routed through the internal *slog.Logger.
Environment variables
| Variable | Default | Description |
|---|---|---|
MINSTACK_HTTP_PORT | — | Port to listen on |
MINSTACK_PORT | 8080 | Port to listen on (fallback) |
MINSTACK_HOST | 0.0.0.0 | Address to bind |
MINSTACK_CORS_ORIGIN | (unset) | Allowed origin(s), comma-separated. Use * to allow all. |
Port resolution
MINSTACK_HTTP_PORT takes precedence over MINSTACK_PORT. Use MINSTACK_PORT only as a fallback — prefer MINSTACK_HTTP_PORT for new projects.