api_plugin.go 872 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package plugins
  2. import (
  3. "encoding/json"
  4. "github.com/grafana/grafana/pkg/models"
  5. )
  6. type ApiPluginRoute struct {
  7. Path string `json:"path"`
  8. Method string `json:"method"`
  9. ReqSignedIn bool `json:"reqSignedIn"`
  10. ReqGrafanaAdmin bool `json:"reqGrafanaAdmin"`
  11. ReqRole models.RoleType `json:"reqRole"`
  12. Url string `json:"url"`
  13. Headers []ApiPluginHeader `json:"headers"`
  14. }
  15. type ApiPlugin struct {
  16. PluginBase
  17. Routes []*ApiPluginRoute `json:"routes"`
  18. }
  19. type ApiPluginHeader struct {
  20. Name string `json:"name"`
  21. Content string `json:"content"`
  22. }
  23. func (app *ApiPlugin) Load(decoder *json.Decoder, pluginDir string) error {
  24. if err := decoder.Decode(&app); err != nil {
  25. return err
  26. }
  27. app.PluginDir = pluginDir
  28. ApiPlugins[app.Id] = app
  29. return nil
  30. }