I'm new with Go/Beego framework and I'm trying to understand how namespace routing works. I have the following:
func init() {
ns :=
beego.NewNamespace("/v1",
beego.NSNamespace("/weather",
beego.NSInclude(&controllers.WeatherController{}),
),
beego.NSNamespace("/scheduler/weather",
beego.NSInclude(&controllers.ScheduleController{}),
),
)
beego.AddNamespace(ns)
}
However when I type 127.0.0.1/v1/weather
or 127.0.0.1/weather
on the browser, there's a page not found response. Same with the other url.
What am I missing here?
Thanks!
Try doing it this way:
func init() {
ns :=
beego.NewNamespace("/v1",
beego.NSRouter("/weather", &controllers.WeatherController{}),
beego.NSRouter("/scheduler/weather",&controllers.ScheduleController{}),
)
beego.AddNamespace(ns) }
The problem was not on router.go but in the controller definition.
Before:
// @router / [put]
func (c *ScheduleController) Put() {
...
}
After:
// @router / [put]
func (c *ScheduleController) Put() {
...
}
The difference was the space in-between @router
and the method definition.