Definition of beego routing group (namespace)

Time:2021-3-9

Case 1

func init(){
    //Define a routing group using the namespace func
    //Use of routing groups:
    //In the outermost layer, a new routing group keyword is usually created: newnamespace
    //The return value is used to call addnamespace func for registration
    ns := beego.NewNamespace("/v1",
  //When you need to define a sub routing group again internally. Available
 //In theory, a namespace can be nested infinitely
  beego.NSNamespace("/user",
  beego.NSRouter(
  "/login",&controllers.AuthController{},
  "post:AcceptLoginParam"),
    ),
   )
    //Register routing group
    beego.AddNamespace(ns)
}

Case 2

//front api
    front := beego.NewNamespace("/v1",
        beego.NSNamespace("/front",
            beego.NSInclude(
                &api.FrontController{},
            ),
        ),
    )
    //login api
    login := beego.NewNamespace("/v1",
        beego.NSNamespace("/login",
        //Automatic matching
            beego.NSInclude(
                &api.FrontController{},
            ),
        ),
    )
    beego.AddNamespace(front, login)

Please refer to the Chinese official website of beego