grpcsrv

package
v0.17.2 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2019 License: Apache-2.0 Imports: 10 Imported by: 0

README

GRPC Server

The package core/workers/grpcsrv provides a default set of configuration for hosting a grpc server in a service.

Configuration

The GRPC server can be configured through these environment variables:

  • GRPC_ADDR the gRPC server listener's network address (default: 0.0.0.0:50051)

Examples

Starting server and exposing the service
srv := grpcsrv.New(&grpcsrv.Config{
    Addr: ":8080",
},
    grpc.StreamInterceptor(paginationmw.StreamServerInterceptor),
    grpc.UnaryInterceptor(paginationmw.UnaryServerInterceptor),
)
srv.Run(ctx, ioutil.Discard)

Documentation

Overview

Package grpcsrv provides a default set of configuration for hosting a grpc server in a service.

Example
package main

import (
	"context"
	"io/ioutil"
	"net/http"
	"time"

	"github.com/LUSHDigital/core/middleware/paginationmw"
	"github.com/LUSHDigital/core/workers/grpcsrv"

	"google.golang.org/grpc"
)

var ctx context.Context

func main() {
	srv := grpcsrv.New(&grpcsrv.Config{
		Addr: ":8080",
	},
		grpc.StreamInterceptor(paginationmw.StreamServerInterceptor),
		grpc.UnaryInterceptor(paginationmw.UnaryServerInterceptor),
	)
	srv.Run(ctx, ioutil.Discard)
}
Output:

Index

Examples

Constants

View Source
const (
	// Port is the default gRPC port used in examples.
	Port = 50051
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Addr string
}

Config represents configuration for the GRPC server.

type Server

type Server struct {
	Connection *grpc.Server
	Now        func() time.Time
	// contains filtered or unexported fields
}

Server represents a collection of functions for starting and running an RPC server.

func New

func New(config *Config, options ...grpc.ServerOption) *Server

New sets up a new grpc server.

func (*Server) Addr

func (gs *Server) Addr() *net.TCPAddr

Addr will block until you have received an address for your server.

func (*Server) Run

func (gs *Server) Run(ctx context.Context, out io.Writer) error

Run will start the gRPC server and listen for requests.

Jump to

Keyboard shortcuts

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