srvgrpc

package module
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2022 License: MIT Imports: 10 Imported by: 0

README

server-grpc

server-grpc implements a service that runs a GRPC server.

Example

package grpc

import (
	srvgrpc "github.com/jamillosantos/server-grpc"
	userpbv1beta1 "github.com/<whatever>/protorepo/build/go/rpc/users/v1beta1"
	"google.golang.org/grpc"
)

func New() *srvgrpc.GRPCServer {
	return srvgrpc.NewGRPCServer(func(s *grpc.Server) error {
		userpbv1beta1.RegisterUserServiceServer(s, NewUserServiceServer())
		return nil
	}, srvgrpc.GRPCServerInitOpts{}).
		WithName("GRPC Server").
		WithConfig(srvgrpc.GRPCServerConfig{
			BindAddress: ":9090",
		})
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotReady = errors.New("service is not ready")

Functions

This section is empty.

Types

type GRPCServer

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

func NewGRPCServer

func NewGRPCServer(name string, registerer Registerer, opts ...Option) *GRPCServer

func (*GRPCServer) Close

func (g *GRPCServer) Close(_ context.Context) error

Close will stop this server.

If the server has not started, or is already stopped, this should do nothing and just return nil.

func (*GRPCServer) IsReady added in v0.2.0

func (g *GRPCServer) IsReady(_ context.Context) error

IsReady will return true if the service is ready to accept requests. This is compliant with the github.com/jamillosantos/application library.

func (*GRPCServer) Listen

func (g *GRPCServer) Listen(_ context.Context) error

Listen will start the server and will block until the service is closed.

If the services is already listining, this should return an error ErrAlreadyListening.

func (*GRPCServer) Name

func (g *GRPCServer) Name() string

Name will return a human identifiable name for this service. Ex: Postgresql Connection.

type Option

type Option func(o *grpcOpts)

func WithBindAddress

func WithBindAddress(bindAddress string) Option

WithBindAddress sets the bind address used to open the GRPC server.

func WithConnectionTimeout

func WithConnectionTimeout(connectionTimeout time.Duration) Option

WithConnectionTimeout set the connection timeout using the grpc.ConnectionTimeout option. The default value is 15 seconds.

func WithStreamInterceptor

func WithStreamInterceptor(interceptors ...grpc.StreamServerInterceptor) Option

WithStreamInterceptor set stream interceptors that will be used.

func WithUnaryInterceptor

func WithUnaryInterceptor(interceptors ...grpc.UnaryServerInterceptor) Option

WithUnaryInterceptor set unary interceptors that will be used.

type Registerer

type Registerer func(*grpc.Server) error

Jump to

Keyboard shortcuts

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