diff --git a/.bra.toml b/.bra.toml index 0b3ce160c2f..c2e1503de2f 100644 --- a/.bra.toml +++ b/.bra.toml @@ -9,7 +9,6 @@ watch_dirs = [ watch_exts = [".go", ".ini"] build_delay = 1500 cmds = [ - ["go", "install"], - ["go", "build"], + ["go", "build", "./pkg/cmd/grafana-pro"], ["./grafana-pro", "web"] ] diff --git a/pkg/cmd/web.go b/pkg/cmd/web.go deleted file mode 100644 index a0d58d7ec71..00000000000 --- a/pkg/cmd/web.go +++ /dev/null @@ -1,97 +0,0 @@ -// Copyright 2014 Unknwon -// Copyright 2014 Torkel Ödegaard - -package cmd - -import ( - "fmt" - "net/http" - "path" - - "github.com/Unknwon/macaron" - "github.com/codegangsta/cli" - "github.com/macaron-contrib/session" - - "github.com/torkelo/grafana-pro/pkg/log" - "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/social" - "github.com/torkelo/grafana-pro/pkg/stores/sqlstore" -) - -var CmdWeb = cli.Command{ - Name: "web", - Usage: "Start Grafana Pro web server", - Description: `Start Grafana Pro server`, - Action: runWeb, - Flags: []cli.Flag{}, -} - -func newMacaron() *macaron.Macaron { - m := macaron.New() - m.Use(middleware.Logger()) - m.Use(macaron.Recovery()) - - mapStatic(m, "public", "public") - mapStatic(m, "public/app", "app") - mapStatic(m, "public/img", "img") - - m.Use(session.Sessioner(session.Options{ - Provider: setting.SessionProvider, - Config: *setting.SessionConfig, - })) - - m.Use(macaron.Renderer(macaron.RenderOptions{ - Directory: path.Join(setting.StaticRootPath, "views"), - IndentJSON: macaron.Env != macaron.PROD, - Delims: macaron.Delims{Left: "[[", Right: "]]"}, - })) - - m.Use(middleware.GetContextHandler()) - return m -} - -func mapStatic(m *macaron.Macaron, dir string, prefix string) { - m.Use(macaron.Static( - path.Join(setting.StaticRootPath, dir), - macaron.StaticOptions{ - SkipLogging: true, - Prefix: prefix, - }, - )) -} - -func runWeb(*cli.Context) { - setting.NewConfigContext() - setting.InitServices() - sqlstore.Init() - social.NewOAuthService() - - // init database - sqlstore.LoadModelsConfig() - if err := sqlstore.NewEngine(); err != nil { - log.Fatal(4, "fail to initialize orm engine: %v", err) - } - - log.Info("Starting Grafana-Pro v.1-alpha") - - m := newMacaron() - routes.Register(m) - - var err error - listenAddr := fmt.Sprintf("%s:%s", setting.HttpAddr, setting.HttpPort) - log.Info("Listen: %v://%s%s", setting.Protocol, listenAddr, setting.AppSubUrl) - switch setting.Protocol { - case setting.HTTP: - err = http.ListenAndServe(listenAddr, m) - case setting.HTTPS: - err = http.ListenAndServeTLS(listenAddr, setting.CertFile, setting.KeyFile, m) - default: - log.Fatal(4, "Invalid protocol: %s", setting.Protocol) - } - - if err != nil { - log.Fatal(4, "Fail to start server: %v", err) - } -} diff --git a/pkg/registry/registry.go b/pkg/registry/registry.go new file mode 100644 index 00000000000..b2a276fb4d2 --- /dev/null +++ b/pkg/registry/registry.go @@ -0,0 +1 @@ +package registry diff --git a/pkg/routes/api/api_account.go b/pkg/routes/api/api_account.go index a2300713dc0..5d4dc4a2926 100644 --- a/pkg/routes/api/api_account.go +++ b/pkg/routes/api/api_account.go @@ -34,7 +34,7 @@ func AddCollaborator(c *middleware.Context) { var model dtos.AddCollaboratorCommand if !c.JsonBody(&model) { - c.JSON(400, utils.DynMap{"message": "Invalid request"}) + c.JsonApiErr(400, "Invalid request", nil) return } diff --git a/pkg/routes/dtos/commands.go b/pkg/routes/dtos/commands.go new file mode 100644 index 00000000000..6770a3cbefd --- /dev/null +++ b/pkg/routes/dtos/commands.go @@ -0,0 +1,11 @@ +package dtos + +type AddCollaboratorCommand struct { + Email string `json:"email" binding:"required"` +} + +type SaveDashboardCommand struct { + Id string `json:"id"` + Title string `json:"title"` + Dashboard map[string]interface{} `json:"dashboard"` +} diff --git a/pkg/routes/dtos/models.go b/pkg/routes/dtos/models.go index c60d5614db3..980e9766344 100644 --- a/pkg/routes/dtos/models.go +++ b/pkg/routes/dtos/models.go @@ -38,10 +38,6 @@ type Collaborator struct { Role string `json:"role"` } -type AddCollaboratorCommand struct { - Email string `json:"email" binding:"required"` -} - func NewCurrentUser(account *models.Account) *CurrentUser { model := &CurrentUser{} if account != nil { @@ -57,9 +53,3 @@ func getGravatarUrl(text string) string { hasher.Write([]byte(strings.ToLower(text))) return fmt.Sprintf("https://secure.gravatar.com/avatar/%x?s=90&default=mm", hasher.Sum(nil)) } - -type SaveDashboardCommand struct { - Id string `json:"id"` - Title string `json:"title"` - Dashboard map[string]interface{} `json:"dashboard"` -} diff --git a/̈́ b/̈́ deleted file mode 100644 index 849fe9f3cc5..00000000000 --- a/̈́ +++ /dev/null @@ -1,29 +0,0 @@ -package api - -type accountInfoDto struct { - Login string `json:"login"` - Email string `json:"email"` - AccountName string `json:"accountName"` - Collaborators []*collaboratorInfoDto `json:"collaborators"` -} - -type collaboratorInfoDto struct { - AccountId int `json:"accountId"` - Email string `json:"email"` - Role string `json:"role"` -} - -type addCollaboratorDto struct { - Email string `json:"email" binding:"required"` -} - -type removeCollaboratorDto struct { - AccountId int `json:"accountId" binding:"required"` -} - -type usingAccountDto struct { - AccountId int `json:"accountId"` - Email string `json:"email"` - Role string `json:"role"` - IsUsing bool -}