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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
/*
Package rpc implements an idiomatic Go interface to collectd's gRPC server.
The functions and types in this package aim to make it easy and convenient to
use collectd's gRPC interface. It supports both client and server code.
Client code
Synopsis:
conn, err := grpc.Dial(*addr, opts...)
if err != nil {
// handle error
}
c := rpc.NewClient(conn)
// Send a ValueList to the server.
if err := c.Write(context.Background(), vl); err != nil {
// handle error
}
// Retrieve matching ValueLists from the server.
ch, err := c.Query(context.Background(), api.Identifier{
Host: "*",
Plugin: "golang",
})
if err != nil {
// handle error
}
for vl := range ch {
// consume ValueList
}
Server code
Synopsis:
type myServer struct {
rpc.Interface
}
func (s *myServer) Write(ctx context.Context, vl *api.ValueList) error {
// implementation
}
func (s *myServer) Query(ctx context.Context, id *api.Identifier) (<-chan *api.ValueList, error) {
// implementation
}
func main() {
sock, err := net.Listen("tcp", ":12345")
if err != nil {
// handle error
}
srv := grpc.NewServer(opts...)
rpc.RegisterServer(srv, &myServer{})
srv.Serve(sock)
}
*/
package rpc // import "collectd.org/rpc"
import (
"context"
"collectd.org/api"
)
// Interface is an idiomatic Go interface for the Collectd gRPC service.
//
// To implement a client, pass a client connection to NewClient() to get back
// an object implementing this interface.
//
// To implement a server, use RegisterServer() to hook an object, which
// implements Interface, up to a gRPC server.
type Interface interface {
api.Writer
Query(context.Context, *api.Identifier) (<-chan *api.ValueList, error)
}
|