MCPcopy Index your code
hub / github.com/260721735/ginRouteAutoRegister

github.com/260721735/ginRouteAutoRegister @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
16 symbols 32 edges 4 files 0 documented · 0%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

ginRouteAutoRegister

making gin route auto registration as simple as irismvc

使用方式

import (
    "github.com/260721735/ginRouteAutoRegister"
)
func Route(engine *gin.Engine) {
    //原生路由注册方式
    engine.GET("/hello", controller.GetTest)
    //自动注册方式
    ginRouteAutoRegister.GinAutoRoute(engine, "/api", NewHelloController())
}

Demo

将HelloController.GetTest注册到http://localhost:8888/api/test路径上

import (
    "github.com/260721735/ginRouteAutoRegister"
    "github.com/gin-gonic/gin"
    "log"
    "net/http"
    "os"
    "os/signal"
    "syscall"
    "time"
)

func main() {
    router := gin.New()
    router.Use(gin.Recovery())
    Route(router)
    srv := &http.Server{
        Addr:    ":8888",
        Handler: router,
    }
    go func() {
        // service connections
        if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
            log.Fatalf("listen: %s\n", err)
        }
    }()
    quit := make(chan os.Signal)
    signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
    <-quit
    //自定义退出时prestop逻辑,这里简单用等待5s
    time.Sleep(1 * time.Second)
    log.Println("Server exiting")
}
func Route(engine *gin.Engine) {
    ginRouteAutoRegister.GinAutoRoute(engine, "/api", NewHelloController())
}

type HelloController struct {
}

func NewHelloController() *HelloController {
    return &HelloController{}
}
func (controller *HelloController) GetTest(c *gin.Context) {
    c.JSON(http.StatusOK, gin.H{
        "code": 0,
        "msg":  "GetTest",
        "data": nil,
    })
}

controller

- controller层
  参照hello_controller.go
  -新建子location,controller层新增方法 GetLoation或PostLocation等
  -将controller注册到route/route.go中Route方法里

router

``` -目前支持AnyOptions

Core symbols most depended-on inside this repo

GinAutoRoute
called by 1
GinMVC.go
ginAutoHand
called by 1
GinMVC.go
NewHelloController
called by 1
demo/controller/hello_controller.go
Route
called by 1
demo/route/route.go
main
called by 0
demo/main.go
GetTest
called by 0
demo/controller/hello_controller.go
GetTestBAD1
called by 0
demo/controller/hello_controller.go
GetTestBAD2
called by 0
demo/controller/hello_controller.go

Shape

Function 8
Method 7
Struct 1

Languages

Go100%

Modules by API surface

demo/controller/hello_controller.go10 symbols
demo/route/route.go3 symbols
GinMVC.go2 symbols
demo/main.go1 symbols

For agents

$ claude mcp add ginRouteAutoRegister \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact