grpcbase

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2019 License: MIT Imports: 6 Imported by: 1

README

Nacelle Base gRPC Process GoDoc CircleCI Coverage Status

Abstract gRPC server process for nacelle.


For a more full-featured gRPC server framework built on nacelle, see scarf.

Usage

The supplied server process is an abstract gRPC server whose behavior is determined by a supplied ServerInitializer interface. This interface has only an Init method that receives application config as well as the gRPC server instance, allowing server implementations to be registered before the server accepts clients. There is an example included in this repository.

The following options can be supplied to the server constructor to tune its behavior.

  • WithTagModifiers registers the tag modifiers to be used when loading process configuration (see below). This can be used to change default hosts and ports, or prefix all target environment variables in the case where more than one gRPC server is registered per application (e.g. health server and application server, data plane and control plane server).
  • WithServerOptions registers options to be supplied directly to the gRPC server constructor.
Configuration

The default process behavior can be configured by the following environment variables.

Environment Variable Default Description
GRPC_HOST 0.0.0.0 The host on which to accept connections.
GRPC_PORT 5000 The port on which to accept connections.

To use the server, initialize a process by passing a Server Initializer to the NewServer constructor. A server initializer is an object with an Init method that takes a nacelle config object (as all process initializer methods do) as well as a *grpc.Server. This hook is provided so that services can be registered to the gRPC server before it begins accepting clients.

The server initializer will have services injected and will receive the nacelle config object on initialization as if it were a process.

To get a better understanding of the full usage, see the example.

Configuration

The default process behavior can be configured by the following environment variables.

Environment Variable Default Description
GRPC_HOST 0.0.0.0 The host on which the server accepts clients.
GRPC_PORT 6000 The port on which the server accepts clients.

Using Multiple Servers

In order to run multiple gRPC servers, tag modifiers can be applied during config registration. For more details on how to do this, see the example.

Remember that multiple services can be registered to the same grpc.Server instance, so multiple processes may not even be necessary depending on your use case.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	GRPCHost string `env:"grpc_host" file:"grpc_host" default:"0.0.0.0"`
	GRPCPort int    `env:"grpc_port" file:"grpc_port" default:"5000"`
}

type ConfigFunc

type ConfigFunc func(*options)

ConfigFunc is a function used to configure an instance of a gRPC Server.

func WithServerOptions

func WithServerOptions(opts ...grpc.ServerOption) ConfigFunc

WithServerOptions sets gRPC options on the underlying server.

func WithTagModifiers

func WithTagModifiers(modifiers ...nacelle.TagModifier) ConfigFunc

WithTagModifiers applies the given tag modifiers on config load.

type Server

type Server struct {
	Logger   nacelle.Logger           `service:"logger"`
	Services nacelle.ServiceContainer `service:"services"`
	Health   nacelle.Health           `service:"health"`
	// contains filtered or unexported fields
}

func NewServer

func NewServer(initializer ServerInitializer, configs ...ConfigFunc) *Server

func (*Server) Init

func (s *Server) Init(config nacelle.Config) (err error)

func (*Server) Start

func (s *Server) Start() error

func (*Server) Stop

func (s *Server) Stop() error

type ServerInitializer

type ServerInitializer interface {
	Init(nacelle.Config, *grpc.Server) error
}

type ServerInitializerFunc

type ServerInitializerFunc func(nacelle.Config, *grpc.Server) error

func (ServerInitializerFunc) Init

func (f ServerInitializerFunc) Init(config nacelle.Config, server *grpc.Server) error

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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