Documentation ¶
Overview ¶
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) }
Index ¶
- func MarshalIdentifier(id *api.Identifier) *pb.Identifier
- func MarshalValue(v api.Value) (*pb.Value, error)
- func MarshalValueList(vl *api.ValueList) (*pb.ValueList, error)
- func RegisterServer(s *grpc.Server, srv Interface)
- func UnmarshalIdentifier(in *pb.Identifier) *api.Identifier
- func UnmarshalValue(in *pb.Value) (api.Value, error)
- func UnmarshalValueList(in *pb.ValueList) (*api.ValueList, error)
- type Interface
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MarshalIdentifier ¶
func MarshalIdentifier(id *api.Identifier) *pb.Identifier
MarshalIdentifier converts an api.Identifier to a pb.Identifier.
func MarshalValue ¶
MarshalValue converts an api.Value to a pb.Value.
func MarshalValueList ¶
MarshalValueList converts an api.ValueList to a pb.ValueList.
func RegisterServer ¶
RegisterServer registers the implementation srv with the gRPC instance s.
func UnmarshalIdentifier ¶
func UnmarshalIdentifier(in *pb.Identifier) *api.Identifier
UnmarshalValue converts a pb.Identifier to an api.Identifier.
func UnmarshalValue ¶
UnmarshalValue converts a pb.Value to an api.Value.
Types ¶
type Interface ¶
type Interface interface { api.Writer Query(context.Context, *api.Identifier) (<-chan *api.ValueList, error) }
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.
func NewClient ¶
func NewClient(conn *grpc.ClientConn) Interface
Newclient returns a wrapper around the gRPC client connection that maps between the Go interface and the gRPC interface.