grpc

package
v0.0.0-...-19169da Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2019 License: MIT Imports: 7 Imported by: 1

README

Nacelle Base gRPC Process

This package contains a base process implementation for a gRPC server. For a more full-featured gRPC framework, see scarf.

Usage

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:"6000"`
}

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 ...config.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:"container"`
	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
Package internal is a generated protocol buffer package.
Package internal is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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