Skip to content

gin

HTTP server module for MinStack, built on Gin.

Installation

sh
go get github.com/go-minstack/gin

Usage

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 with sensible defaults (recovery, logger).

Environment variables

VariableDefaultDescription
MINSTACK_HOST0.0.0.0Address to bind
MINSTACK_PORT8080Port to listen on
MINSTACK_CORS_ORIGIN(unset)Allowed origin(s), comma-separated. Use * to allow all.