Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

Sub-route Alias Guide

When using type-definded sub-route, you can add an alias to customize the route name.

Here we will use Gin as example.

📁
|-📁foo
| |-bar.go ✨
| |-baz.go ✨
|-main.go
|-go.mod

Defining Sub-routes

./foo/bar.go

package foo

import "github.com/gin-gonic/gin"

// routegen alias=bar-alias
type Bar struct{}

func (*Bar) GET(g *gin.Context) { /* your code */ }

./foo/baz.go

package foo

import "github.com/gin-gonic/gin"

// routegen alias=baz-alias
type Baz struct{}

func (*Baz) GET(g *gin.Context) {}

Output

./main_gen.go

func Build(g *gin.Engine) {
	bar := &routegen_r.Bar{}
	g.GET("/foo/bar-alias", bar.GET)
	baz := &routegen_r.Baz{}
	g.GET("/foo/baz-alias", baz.GET)
}