plugin.go 881 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. package main
  2. import (
  3. "golang.org/x/net/context"
  4. "log"
  5. "github.com/grafana/grafana/pkg/tsdb/plugins/proto"
  6. shared "github.com/grafana/grafana/pkg/tsdb/plugins/shared"
  7. plugin "github.com/hashicorp/go-plugin"
  8. )
  9. type Tsdb struct {
  10. plugin.NetRPCUnsupportedPlugin
  11. }
  12. func (Tsdb) Get(ctx context.Context, req *proto.TsdbRequest) (*proto.TsdbResponse, error) {
  13. log.Print("Tsdb.Get() from plugin")
  14. return &proto.TsdbResponse{
  15. MetaJson: "from plugins! meta meta",
  16. }, nil
  17. }
  18. func main() {
  19. plugin.Serve(&plugin.ServeConfig{
  20. HandshakeConfig: plugin.HandshakeConfig{
  21. ProtocolVersion: 1,
  22. MagicCookieKey: "BASIC_PLUGIN",
  23. MagicCookieValue: "hello",
  24. },
  25. Plugins: map[string]plugin.Plugin{
  26. "tsdb_mock": &shared.TsdbPluginImpl{Plugin: &Tsdb{}},
  27. },
  28. // A non-nil value here enables gRPC serving for this plugin...
  29. GRPCServer: plugin.DefaultGRPCServer,
  30. })
  31. }