engine

package module
v0.0.0-...-14d8bfa Latest Latest
Warning

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

Go to latest
Published: May 3, 2019 License: Apache-2.0 Imports: 9 Imported by: 1

README

Engine

Godoc

A Pluggable gRPC Microservice Framework

go get github.com/autom8ter/engine

License: MIT


//Embeded driver.PluginFunc is used to satisfy the driver.Plugin interface
type Example struct {
	driver.PluginFunc
}

//create new example with the generated registration function from grpc
func NewExample() Example {
	e := Example{}
	e.PluginFunc = func(s *grpc.Server) {
		examplepb.RegisterEchoServiceServer(s, e)
	}
	return e
}
//examplepb methods excluded for brevity

func main() {
	if err := engine.New("tcp", ":8080").With(
		//general options:
		config.WithDebug(),                    //adds verbose logging for development
		config.WithMaxConcurrentStreams(1000), //sets max concurrent server streams

		//plugins:
		config.WithChannelz(),   //adds a channelz service
		config.WithReflection(), //adds a reflection service
		config.WithHealthz(),    //adds a healthz service
		config.WithPlugins(examplepb.NewExample()),

		//unary middleware:
		config.WithUnaryUUIDMiddleware(),     //adds a unary uuid middleware
		config.WithUnaryTraceMiddleware(),    // adds a streaming opentracing middleware
		config.WithUnaryLoggingMiddleware(),  // adds a unary logging rmiddleware
		config.WithUnaryRecoveryMiddleware(), // adds a unary recovery middleware

		//streaming middleware
		config.WithStreamUUIDMiddleware(),     //adds a streaming uuid middleware
		config.WithStreamTraceMiddleware(),    // adds a streaming opentracing middleware
		config.WithStreamLoggingMiddleware(),  //adds a streaming logging middleware
		config.WithStreamRecoveryMiddleware(), // adds a streaming recovery middleware

	).Serve(); err != nil {
		log.Fatalln(err.Error())
	}
}

The above engine configuration(minus the example service) can be created with:

engine.Default(network, addr string, debug bool).With(config.WithPlugins(...add plugins here))

Driver

github.com/autom8ter/engine/driver

driver.Plugin is used to register grpc server implementations.


//Plugin is an interface for representing gRPC server implementations.
type Plugin interface {
	RegisterWithServer(*grpc.Server)
}

//PluginFunc implements the Plugin interface.
type PluginFunc func(*grpc.Server)

//RegisterWithServer is an interface for representing gRPC server implementations.
func (p PluginFunc) RegisterWithServer(s *grpc.Server) {
	p(s)
}


Features/Scope/Roadmap


Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Serve

func Serve(addr string, debug bool, plugs ...driver.Plugin) error

Serve creates starts a gRPC server without the need to create an engine instance

Types

type Engine

type Engine interface {
	Proxy(server *http.Server) error
	With(opts ...config.Option) *Runtime
	Config() *config.Config
	Shutdown(ctx context.Context)
	Serve() error
}

Engine is an interface used to describe a server runtime

func Default

func Default(network, addr string, debug bool) Engine

New creates a new engine intstance.

func New

func New(network, addr string, debug bool) Engine

New creates a new engine intstance.

type Runtime

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

Runtime is an implementation of the engine API.

func (*Runtime) Config

func (e *Runtime) Config() *config.Config

Config returns the runtimes current configuration

func (*Runtime) Proxy

func (e *Runtime) Proxy(server *http.Server) error

Serve starts the runtime gRPC server.

func (*Runtime) Serve

func (e *Runtime) Serve() error

Serve starts the runtime gRPC server.

func (*Runtime) Shutdown

func (e *Runtime) Shutdown(ctx context.Context)

Shutdown gracefully closes the grpc server.

func (*Runtime) With

func (e *Runtime) With(opts ...config.Option) *Runtime

With wraps the runtimes config with config options ref: github.com/autom8ter/engine/config/options.go

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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