Skip to content

Instantly share code, notes, and snippets.

@anidotnet
Created January 1, 2015 11:00
Show Gist options
  • Save anidotnet/ac117922038aa987322d to your computer and use it in GitHub Desktop.
Save anidotnet/ac117922038aa987322d to your computer and use it in GitHub Desktop.
package routers
import (
"github.com/astaxie/beego"
"apidemo/controllers"
)
func init() {
ns := beego.NewNamespace("/v1",
beego.NSNamespace("/user",
beego.NSInclude(
&controllers.UserController{},
),
),
)
beego.AddNamespace(ns)
}
package controllers
import (
"github.com/astaxie/beego"
"apidemo/models"
)
func (c *UserController) URLMapping() {
c.Mapping("Get", c.Get)
}
type UserController struct {
beego.Controller
}
// @router / [get]
func (u *UserController) Get() {
users := models.GetAllUsers()
u.Data["json"] = users
u.ServeJson()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment