rpcplatform

package module
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2025 License: Apache-2.0 Imports: 25 Imported by: 0

README

RPCPlatform

Build PkgGoDev GoReportCard

An easy-to-use platform for creating microservices without complex infrastructure solutions. Only etcd required. Out of the box you get a service discovery, tracing between services and other useful things. gRPC is used for communication between services.

etcd required

If there is no etcd in your infrastructure, you can install it from a docker container for tests:

docker run -d \
  -p 2379:2379 \
  -p 2380:2380 \
  --name etcd gcr.io/etcd-development/etcd:v3.6.5 \
  /usr/local/bin/etcd \
  --name etcd \
  --initial-advertise-peer-urls http://127.0.0.1:2380 --listen-peer-urls http://0.0.0.0:2380 \
  --advertise-client-urls http://127.0.0.1:2379 --listen-client-urls http://0.0.0.0:2379 \
  --initial-cluster etcd=http://127.0.0.1:2380

Of course, you can use docker in production or install etcd using your favorite package manager. Just remember that the example above is for testing purposes!

Usage examples

  • QuickStart: contains the simplest example without additional features
  • OpenTelemetry: example with connecting distributed tracing systems
  • Attributes: example using additional settings for client and server

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// PlatformOptions provides options used when creating new RPCPlatform.
	PlatformOptions = options.Platform{}

	// ClientOptions provides options used when creating new Client.
	ClientOptions = options.Client{}

	// ServerOptions provides options used when creating new Server.
	ServerOptions = options.Server{}
)

Functions

This section is empty.

Types

type Attributes

type Attributes = attributes.Attributes

Attributes provides server attribute values.

func NewAttributes added in v1.5.0

func NewAttributes() *Attributes

NewAttributes returns attributes with default values.

type Client

type Client struct {
	// contains filtered or unexported fields
}

func (*Client) Client

func (c *Client) Client() *grpc.ClientConn

Client return the original gRPC ClientConn object.

func (*Client) ID added in v1.5.0

func (c *Client) ID() string

ID return the client identifier.

type ClientOption added in v1.5.0

type ClientOption = func(*config.Client)

ClientOption is used to pass ClientOptions when creating a new Client

type PlatformOption added in v1.5.0

type PlatformOption = func(*config.Platform)

PlatformOption is used to pass PlatformOptions when creating a new RPCPlatform

type RPCPlatform

type RPCPlatform struct {
	// contains filtered or unexported fields
}

func New

func New(etcdPrefix string, etcdClient *etcd.Client, options ...PlatformOption) (*RPCPlatform, error)

New creates an RPCPlatform object for further creation of clients and servers. All methods of this object are thread safe. You can create this object once and use it in different places in your program.

func (*RPCPlatform) Lookup added in v1.4.0

func (p *RPCPlatform) Lookup(ctx context.Context, name string, watch bool) (<-chan map[string]*ServerInfo, error)

Lookup returns information about available servers by name. If the watch is set to true, a new portion of data will be provided with each change. Otherwise the channel will be closed immediately after the first data is written. The keys of the returned map are server IDs.

func (*RPCPlatform) NewClient

func (p *RPCPlatform) NewClient(target string, options ...ClientOption) (*Client, error)

NewClient creates a new client. You need to provide the target server name.

func (*RPCPlatform) NewServer

func (p *RPCPlatform) NewServer(name, addr string, options ...ServerOption) (*Server, error)

NewServer creates a new server. You need to provide the server name and listening address.

type Server

type Server struct {
	// contains filtered or unexported fields
}

func (*Server) ID added in v1.4.0

func (s *Server) ID() string

ID return the server identifier.

func (*Server) Serve

func (s *Server) Serve() error

Serve starts the gRPC Server and return error if it occurs.

func (*Server) Server

func (s *Server) Server() *grpc.Server

Server return the original gRPC Server object.

type ServerInfo added in v1.5.0

type ServerInfo struct {
	Address    string
	Attributes *Attributes
}

ServerInfo is the state of the server in etcd.

type ServerOption added in v1.5.0

type ServerOption = func(*config.Server)

ServerOption is used to pass ServerOptions when creating a new Server

Directories

Path Synopsis
examples
internal

Jump to

Keyboard shortcuts

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