Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to make nested router #2

Open
tieubao opened this issue Jul 7, 2015 · 0 comments
Open

How to make nested router #2

tieubao opened this issue Jul 7, 2015 · 0 comments
Labels

Comments

@tieubao
Copy link
Member

tieubao commented Jul 7, 2015

I want to implement RESTful API. But the following Beego code cannot make it.

POST /events/
GET /events/:slug
GET /events/:id

POST /events/:slug/sessions/
GET /events/:slug/sessions/:id

Please reference to the source code at: https://github.com/dwarvesf/liulo/blob/4def0c9f879dc2d855697952208cc42c3dcdb34b/routers/router.go

package routers

import (
    "github.com/astaxie/beego"
    "github.com/dwarvesf/liulo/controllers"
)

func init() {

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

    ns := beego.NewNamespace("/v1",

        // Authentication
        beego.NSNamespace("/users",
            beego.NSRouter("/sign_up", &controllers.UserController{}, "POST:SignUp"),
            beego.NSRouter("/sign_in", &controllers.UserController{}, "POST:SignIn"),
            beego.NSRouter("/", &controllers.UserController{}, "GET:GetCurrentUser"),
        ),

        // Events
        beego.NSNamespace("/events",
            beego.NSRouter("/", &controllers.EventController{},
                "POST:Post"),
            beego.NSRouter("/:slug", &controllers.EventController{},
                "GET:GetBySlug"),
            beego.NSRouter("/:eventId",
                &controllers.EventController{}, "GET:GetById"),
        ),

        // Sessions
        beego.NSNamespace("/events/:slug:string/sessions",
            beego.NSRouter("/", &controllers.SessionController{},
                "GET:GetAll;POST:Post"),
            beego.NSRouter("/:sessionId",
                &controllers.SessionController{},
                "GET:GetById"),
        ),

        beego.NSNamespace("/events/:slug:string/sessions/:sessionId/questions",
            beego.NSRouter("/", &controllers.QuestionController{},
                "GET:GetAll;POST:Post"),
            beego.NSRouter("/:questionId", &controllers.QuestionController{},
                "GET:GetById"),
        ),
    )

    beego.AddNamespace(ns)
}
@tieubao tieubao added the beego label Jul 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant