错误信息
# github.com/study/gincms/router
duplicate "".(*IndexController).Index-fm.stkobj
<autogenerated>:1: symbol "".(*IndexController).Index-fm.stkobj listed multiple times
golang 版本
go version go1.12.1 windows/amd64
业务代码截图
package router
import (
"github.com/study/gincms/controller/admin"
"github.com/study/gincms/controller/home"
"github.com/gin-gonic/gin"
)
/**
路由初始化
*/
func RouterInit() *gin.Engine {
r := gin.Default()
//前台 API 路由
homeIndex := new(home.IndexController)
r.GET("/", homeIndex.Index)
homeUrl := r.Group("/home")
{
homeUrl.GET("/index/index", homeIndex.Index)
}
//后台 API 路由
index := new(admin.IndexController)
adminUrl := r.Group("/admin")
{
adminUrl.GET("/index/index", index.Index)
}
return r
}
controller
package admin
import (
"net/http"
"github.com/gin-gonic/gin"
)
type IndexController struct{}
func (this *IndexController) Index(ctx *gin.Context) {
ctx.JSON( http.StatusOK, gin.H{
"message": "111",
})
}
package home
import (
"net/http"
"github.com/gin-gonic/gin"
)
type IndexController struct{}
func (this *IndexController) Index(ctx *gin.Context) {
ctx.JSON( http.StatusOK, gin.H{
"message": "2222",
})
}
1
leon0903 2019-03-26 17:39:16 +08:00
我觉得还是改名字吧。。。。HomeController, AdminController、
|
2
insert000 OP @leon0903 测试了一下,gin 框架下面,如果是不同包同名的 struct,方法名不同也可以运行。不知道是不是 gin 解析路由有什么特别的要求
|
3
webluoye 2019-03-26 17:44:05 +08:00
逻辑上是不应该冲突的,都不在一个包了
|
5
reus 2019-03-27 16:19:30 +08:00
编译器的 bug
|
6
skiy 2019-03-29 14:30:06 +08:00
```
package router import ( cAdmin "github.com/study/gincms/controller/admin" cIndex "github.com/study/gincms/controller/home" "github.com/gin-gonic/gin" ) ``` 用别名啊。 |