rpc

package
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 4, 2024 License: ISC Imports: 9 Imported by: 0

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

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

func MarshalValue(v api.Value) (*pb.Value, error)

MarshalValue converts an api.Value to a pb.Value.

func MarshalValueList

func MarshalValueList(vl *api.ValueList) (*pb.ValueList, error)

MarshalValueList converts an api.ValueList to a pb.ValueList.

func RegisterServer

func RegisterServer(s *grpc.Server, srv Interface)

RegisterServer registers the implementation srv with the gRPC instance s.

func UnmarshalIdentifier

func UnmarshalIdentifier(in *pb.Identifier) *api.Identifier

UnmarshalIdentifier converts a pb.Identifier to an api.Identifier.

func UnmarshalValue

func UnmarshalValue(in *pb.Value) (api.Value, error)

UnmarshalValue converts a pb.Value to an api.Value.

func UnmarshalValueList

func UnmarshalValueList(in *pb.ValueList) (*api.ValueList, error)

UnmarshalValueList converts a pb.ValueList to an api.ValueList.

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.

Directories

Path Synopsis
Package proto is a generated protocol buffer package.
Package proto is a generated protocol buffer package.
types
Package types is a generated protocol buffer package.
Package types is a generated protocol buffer package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL