hooks.go 610 B

123456789101112131415161718192021222324252627282930
  1. package hooks
  2. import (
  3. "github.com/grafana/grafana/pkg/api/dtos"
  4. "github.com/grafana/grafana/pkg/registry"
  5. )
  6. type IndexDataHook func(indexData *dtos.IndexViewData)
  7. type HooksService struct {
  8. indexDataHooks []IndexDataHook
  9. }
  10. func init() {
  11. registry.RegisterService(&HooksService{})
  12. }
  13. func (srv *HooksService) Init() error {
  14. return nil
  15. }
  16. func (srv *HooksService) AddIndexDataHook(hook IndexDataHook) {
  17. srv.indexDataHooks = append(srv.indexDataHooks, hook)
  18. }
  19. func (srv *HooksService) RunIndexDataHooks(indexData *dtos.IndexViewData) {
  20. for _, hook := range srv.indexDataHooks {
  21. hook(indexData)
  22. }
  23. }