nycynik
nycynik

Reputation: 7541

How to mix namespace and restful routing in BeeGo

I'm building a simple project that has an API and serves a dashboard alongside it.

My goal is to have a namespace router (for swagger docs) and a restful router (for the web pages) in the same project, is this possible?

I'm able to get the normal router to show fine, but the API does not show.

I tried checking with http://127.0.0.1:8088/listconf?command=router and it only shows the restful router.

Here is my router.go

package routers

import (
    "futureapi/controllers"

    beego "github.com/beego/beego/v2/server/web"
)

func init() {
    beego.Router("/", &controllers.MainController{})

}

and the api route

package routers

import (
    "futureapi/controllers"

    beego "github.com/beego/beego/v2/server/web"
)

func init() {
    ns := beego.NewNamespace("/v1",
        beego.NSNamespace("/reward",
            beego.NSInclude(
                &controllers.RewardController{},
            ),
        )
    )
    beego.AddNamespace(ns)
}

The swagger docs are generated, but they say, 'no operations found'. The pages load, but the API does not.

If this does not work out, I can split them into two services, but it would be nice since things are small now to just leave them together.

Upvotes: 3

Views: 441

Answers (0)

Related Questions