mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
moved all http route handling into single package named api
This commit is contained in:
parent
1663cbbb34
commit
973b9cad36
49
pkg/api/api.go
Normal file
49
pkg/api/api.go
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/Unknwon/macaron"
|
||||||
|
"github.com/torkelo/grafana-pro/pkg/api/dtos"
|
||||||
|
"github.com/torkelo/grafana-pro/pkg/middleware"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Register(m *macaron.Macaron) {
|
||||||
|
auth := middleware.Auth()
|
||||||
|
|
||||||
|
// index
|
||||||
|
m.Get("/", auth, Index)
|
||||||
|
m.Post("/logout", LogoutPost)
|
||||||
|
m.Post("/login", LoginPost)
|
||||||
|
|
||||||
|
// login
|
||||||
|
m.Get("/login", Index)
|
||||||
|
m.Get("/login/:name", OAuthLogin)
|
||||||
|
|
||||||
|
// account
|
||||||
|
m.Get("/account/", auth, Index)
|
||||||
|
m.Get("/api/account/", auth, GetAccount)
|
||||||
|
m.Post("/api/account/collaborators/add", auth, AddCollaborator)
|
||||||
|
m.Get("/api/account/others", auth, GetOtherAccounts)
|
||||||
|
|
||||||
|
// user register
|
||||||
|
m.Get("/register/*_", Index)
|
||||||
|
m.Post("/api/account", CreateAccount)
|
||||||
|
|
||||||
|
// dashboards
|
||||||
|
m.Get("/dashboard/*", auth, Index)
|
||||||
|
m.Get("/api/dashboards/:slug", auth, GetDashboard)
|
||||||
|
m.Get("/api/search/", auth, Search)
|
||||||
|
m.Post("/api/dashboard/", auth, PostDashboard)
|
||||||
|
m.Delete("/api/dashboard/:slug", auth, DeleteDashboard)
|
||||||
|
|
||||||
|
// rendering
|
||||||
|
m.Get("/render/*", auth, RenderToPng)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Index(ctx *middleware.Context) {
|
||||||
|
ctx.Data["User"] = dtos.NewCurrentUser(ctx.UserAccount)
|
||||||
|
ctx.HTML(200, "index")
|
||||||
|
}
|
||||||
|
|
||||||
|
func NotFound(ctx *middleware.Context) {
|
||||||
|
ctx.Handle(404, "index", nil)
|
||||||
|
}
|
@ -1,9 +1,9 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/torkelo/grafana-pro/pkg/api/dtos"
|
||||||
"github.com/torkelo/grafana-pro/pkg/middleware"
|
"github.com/torkelo/grafana-pro/pkg/middleware"
|
||||||
"github.com/torkelo/grafana-pro/pkg/models"
|
"github.com/torkelo/grafana-pro/pkg/models"
|
||||||
"github.com/torkelo/grafana-pro/pkg/routes/dtos"
|
|
||||||
"github.com/torkelo/grafana-pro/pkg/utils"
|
"github.com/torkelo/grafana-pro/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
@ -1,9 +1,9 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/torkelo/grafana-pro/pkg/api/dtos"
|
||||||
"github.com/torkelo/grafana-pro/pkg/middleware"
|
"github.com/torkelo/grafana-pro/pkg/middleware"
|
||||||
"github.com/torkelo/grafana-pro/pkg/models"
|
"github.com/torkelo/grafana-pro/pkg/models"
|
||||||
"github.com/torkelo/grafana-pro/pkg/routes/dtos"
|
|
||||||
"github.com/torkelo/grafana-pro/pkg/utils"
|
"github.com/torkelo/grafana-pro/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
@ -1,10 +1,10 @@
|
|||||||
package login
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/torkelo/grafana-pro/pkg/api/dtos"
|
||||||
"github.com/torkelo/grafana-pro/pkg/log"
|
"github.com/torkelo/grafana-pro/pkg/log"
|
||||||
"github.com/torkelo/grafana-pro/pkg/middleware"
|
"github.com/torkelo/grafana-pro/pkg/middleware"
|
||||||
"github.com/torkelo/grafana-pro/pkg/models"
|
"github.com/torkelo/grafana-pro/pkg/models"
|
||||||
"github.com/torkelo/grafana-pro/pkg/routes/dtos"
|
|
||||||
"github.com/torkelo/grafana-pro/pkg/utils"
|
"github.com/torkelo/grafana-pro/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package login
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
@ -12,9 +12,9 @@ import (
|
|||||||
"github.com/codegangsta/cli"
|
"github.com/codegangsta/cli"
|
||||||
"github.com/macaron-contrib/session"
|
"github.com/macaron-contrib/session"
|
||||||
|
|
||||||
|
"github.com/torkelo/grafana-pro/pkg/api"
|
||||||
"github.com/torkelo/grafana-pro/pkg/log"
|
"github.com/torkelo/grafana-pro/pkg/log"
|
||||||
"github.com/torkelo/grafana-pro/pkg/middleware"
|
"github.com/torkelo/grafana-pro/pkg/middleware"
|
||||||
"github.com/torkelo/grafana-pro/pkg/routes"
|
|
||||||
"github.com/torkelo/grafana-pro/pkg/setting"
|
"github.com/torkelo/grafana-pro/pkg/setting"
|
||||||
"github.com/torkelo/grafana-pro/pkg/social"
|
"github.com/torkelo/grafana-pro/pkg/social"
|
||||||
"github.com/torkelo/grafana-pro/pkg/stores/sqlstore"
|
"github.com/torkelo/grafana-pro/pkg/stores/sqlstore"
|
||||||
@ -78,7 +78,7 @@ func runWeb(*cli.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
m := newMacaron()
|
m := newMacaron()
|
||||||
routes.Register(m)
|
api.Register(m)
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
listenAddr := fmt.Sprintf("%s:%s", setting.HttpAddr, setting.HttpPort)
|
listenAddr := fmt.Sprintf("%s:%s", setting.HttpAddr, setting.HttpPort)
|
||||||
|
@ -1,51 +0,0 @@
|
|||||||
package routes
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/Unknwon/macaron"
|
|
||||||
"github.com/torkelo/grafana-pro/pkg/middleware"
|
|
||||||
"github.com/torkelo/grafana-pro/pkg/routes/api"
|
|
||||||
"github.com/torkelo/grafana-pro/pkg/routes/dtos"
|
|
||||||
"github.com/torkelo/grafana-pro/pkg/routes/login"
|
|
||||||
)
|
|
||||||
|
|
||||||
func Register(m *macaron.Macaron) {
|
|
||||||
auth := middleware.Auth()
|
|
||||||
|
|
||||||
// index
|
|
||||||
m.Get("/", auth, Index)
|
|
||||||
m.Post("/logout", login.LogoutPost)
|
|
||||||
m.Post("/login", login.LoginPost)
|
|
||||||
|
|
||||||
// login
|
|
||||||
m.Get("/login", Index)
|
|
||||||
m.Get("/login/:name", login.OAuthLogin)
|
|
||||||
|
|
||||||
// account
|
|
||||||
m.Get("/account/", auth, Index)
|
|
||||||
m.Get("/api/account/", auth, api.GetAccount)
|
|
||||||
m.Post("/api/account/collaborators/add", auth, api.AddCollaborator)
|
|
||||||
m.Get("/api/account/others", auth, api.GetOtherAccounts)
|
|
||||||
|
|
||||||
// user register
|
|
||||||
m.Get("/register/*_", Index)
|
|
||||||
m.Post("/api/account", api.CreateAccount)
|
|
||||||
|
|
||||||
// dashboards
|
|
||||||
m.Get("/dashboard/*", auth, Index)
|
|
||||||
m.Get("/api/dashboards/:slug", auth, api.GetDashboard)
|
|
||||||
m.Get("/api/search/", auth, api.Search)
|
|
||||||
m.Post("/api/dashboard/", auth, api.PostDashboard)
|
|
||||||
m.Delete("/api/dashboard/:slug", auth, api.DeleteDashboard)
|
|
||||||
|
|
||||||
// rendering
|
|
||||||
m.Get("/render/*", auth, api.RenderToPng)
|
|
||||||
}
|
|
||||||
|
|
||||||
func Index(ctx *middleware.Context) {
|
|
||||||
ctx.Data["User"] = dtos.NewCurrentUser(ctx.UserAccount)
|
|
||||||
ctx.HTML(200, "index")
|
|
||||||
}
|
|
||||||
|
|
||||||
func NotFound(ctx *middleware.Context) {
|
|
||||||
ctx.Handle(404, "index", nil)
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user