gin

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package gin is a router plugin for github.com/gin-gonic/gin. It statically recognizes route registrations on a *gin.Engine or *gin.RouterGroup:

r.GET("/users/:id", GetUser)                 // method-specific: GET/POST/PUT/DELETE/PATCH/HEAD/OPTIONS
r.Any("/health", HealthCheck)                // every HTTP method
r.Handle("GET", "/users/:id", GetUser)       // explicit method as a compile-time-constant string
r.Match([]string{"GET", "POST"}, "/x", H)    // several explicit methods
v1 := r.Group("/api/v1")                      // a group variable carries a path prefix,
v1.GET("/users", ListUsers)                  //   accumulated across nested groups -> "/api/v1/users"

It does not import the real gin: recognition is pure go/types path/name matching against the analyzed target's own type-checked packages, the same mechanism internal/router/nethttp uses for *http.ServeMux — gota's own build never depends on gin.

Handlers are the LAST argument of a route call (gin's route methods are variadic, "handlers ...HandlerFunc"; the earlier arguments are middleware). Gin handlers are func(c *gin.Context), a shape unlike net/http's, so this plugin pairs with the gin inference dialect (inference.Gin()), not inference.NetHTTP().

Path parameters use gin's ":name" syntax, translated to OpenAPI's "{name}". A catch-all "*name" segment has no OpenAPI path-template equivalent, so a route containing one is declined.

The prefix of a route travels through the group VARIABLE it's registered on (object identity), not lexical nesting: "v1 := r.Group("/api/v1")" then "v1.GET(...)". groupPrefix resolves that chain. Known, deliberate residual gaps (declined, not guessed):

  • A function taking a *gin.RouterGroup parameter and registering routes on it (e.g. "func registerV1(rg *gin.RouterGroup) { rg.GET("/tags", ...) }") — its routes are declined, NOT walked at the empty prefix. This is the OPPOSITE posture from the chi plugin: gin group functions register RELATIVE paths (rg.GET("/tags") means the group's own prefix + "/tags"), so walking one at the empty prefix would emit "/tags" — a path gin never serves. A *gin.RouterGroup parameter has no prefix a single-package Extract can recover, so it's declined.
  • A group variable assigned more than once (ambiguous prefix), a non-constant Group path, a group whose receiver chain can't be resolved to a constant prefix, and a "*name" catch-all path.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Plugin

type Plugin struct{}

func New

func New() *Plugin

func (*Plugin) Extract

func (p *Plugin) Extract(pkg *packages.Package) ([]router.Route, error)

func (*Plugin) Name

func (p *Plugin) Name() string

Jump to

Keyboard shortcuts

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