File: service.go

package info (click to toggle)
golang-github-grafana-grafana-plugin-model 0.0~git20200514.df1eb6b-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 160 kB
  • sloc: makefile: 14
file content (42 lines) | stat: -rw-r--r-- 1,082 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package datasource

import (
	"context"

	plugin "github.com/hashicorp/go-plugin"
	"google.golang.org/grpc"
)

type DatasourcePlugin interface {
	Query(ctx context.Context, req *DatasourceRequest) (*DatasourceResponse, error)
}

type DatasourcePluginImpl struct {
	plugin.NetRPCUnsupportedPlugin
	Plugin DatasourcePlugin
}

func (p *DatasourcePluginImpl) GRPCServer(broker *plugin.GRPCBroker, s *grpc.Server) error {
	RegisterDatasourcePluginServer(s, &GRPCServer{p.Plugin})
	return nil
}

func (p *DatasourcePluginImpl) GRPCClient(ctx context.Context, broker *plugin.GRPCBroker, c *grpc.ClientConn) (interface{}, error) {
	return &GRPCClient{NewDatasourcePluginClient(c)}, nil
}

type GRPCClient struct {
	DatasourcePluginClient
}

func (m *GRPCClient) Query(ctx context.Context, req *DatasourceRequest) (*DatasourceResponse, error) {
	return m.DatasourcePluginClient.Query(ctx, req)
}

type GRPCServer struct {
	DatasourcePlugin
}

func (m *GRPCServer) Query(ctx context.Context, req *DatasourceRequest) (*DatasourceResponse, error) {
	return m.DatasourcePlugin.Query(ctx, req)
}