Adds backend hooks service so extensions can modify index data

This commit is contained in:
Torkel Ödegaard
2018-10-12 11:26:42 +02:00
parent b5e1a8d7be
commit 8c9939df72
6 changed files with 103 additions and 77 deletions
+30
View File
@@ -0,0 +1,30 @@
package hooks
import (
"github.com/grafana/grafana/pkg/api/dtos"
"github.com/grafana/grafana/pkg/registry"
)
type IndexDataHook func(indexData *dtos.IndexViewData)
type HooksService struct {
indexDataHooks []IndexDataHook
}
func init() {
registry.RegisterService(&HooksService{})
}
func (srv *HooksService) Init() error {
return nil
}
func (srv *HooksService) AddIndexDataHook(hook IndexDataHook) {
srv.indexDataHooks = append(srv.indexDataHooks, hook)
}
func (srv *HooksService) RunIndexDataHooks(indexData *dtos.IndexViewData) {
for _, hook := range srv.indexDataHooks {
hook(indexData)
}
}