go - Go 的 Echo 框架路由器问题?
问题描述
所以这可能是我对 Golang 的有限理解,因为我还在学习它。但是我在我的应用程序的主包/文件中构建了一个工作路由器功能,传入上下文并且工作正常。
但是,当我将它移到它自己的包中时,它停止工作,我来宾这与不从主包中传递上下文有关吗?
所以这有效:
func router(e *echo.Echo) {
addresController := &controllers.AddressController{
config.NewController(),
}
//Address Routes
address := e.Group("/address")
address.GET("/all", func(c echo.Context) error {
return addresController.AddressList(c)
})
}
像这样加载到主函数中,
func main() {
//Build The Echo Framework
e := echo.New()
//Load Router Function
router(e)
//Start Echo Web Server
e.Logger.Fatal(e.Start(":5060"))
}
但是当我在主函数中使用这个时,
router.BuidlRoutes(e)
并将所有地址路由放入BuildRoutes
函数中,我得到空结果。
谢谢,
更新
我BuildRouter
要求的功能:
func BuidlRoutes(e *echo.Echo) {
addresController := &controllers.AddressController{
config.NewController(),
}
//Address Routes
address := e.Group("/address")
address.GET("/all", func(c echo.Context) error {
return addresController.AddressList(c)
})
address.GET("/id/:id", func(c echo.Context) error {
return addresController.AddressByID(c)
})
}
这是我的Address Controller Struct
type AddressController struct {
*config.MyController
}
这个地址控制器正在加载一个 MyController,
type MyController struct {
*DBSettings
}
func NewController() *MyController {
return &MyController{}
}
解决方案
推荐阅读
- r - 使用 geom_tile 在 x 轴下方添加轨迹颜色
- c++ - 如何在不复制 C++ 中的下一行的情况下阅读到行尾?
- hl7-fhir - FHIR 添加自定义 .create
- apache-kafka - 使用 kafka 在同一微服务的 2 个实例之间进行数据同步
- bash - '\r':找不到命令 - .bashrc
- java - 无法在最新的 Google Play 结算库中解析符号“BillingHelper”
- python-3.x - 发生异常时 ThreadPoolExecutor 继续等待
- google-cloud-platform - gcloud util 安装在 Windows 10 上崩溃
- r - 在 dplyr 1.0.0 中使用 mutate() 和 cross() 从多个变量创建新变量
- c# - 即使重新启动后,我如何每天回忆方法?