flexgrpc

package module
v0.0.0-...-fb16cc2 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2021 License: Apache-2.0 Imports: 9 Imported by: 0

README

flexgrpc

A flex compatible grpc server

The package flexgrpc 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 := flexgrpc.New(
    &flexgrpc.Config{Addr: ":8080"},
    grpc.ConnectionTimeout(10*time.Second),
)
_ = srv.Run(ctx)

Documentation

Overview

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

Example
package main

import (
	"context"
	"time"

	"github.com/go-flexible/flexgrpc"
	"google.golang.org/grpc"
)

func main() {
	srv := flexgrpc.New(
		&flexgrpc.Config{Addr: ":8080"},
		grpc.ConnectionTimeout(10*time.Second),
	)
	_ = srv.Run(context.Background())
}
Output:

Index

Examples

Constants

View Source
const Port = 50051

Port is the default gRPC port used in examples.

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) Halt

func (gs *Server) Halt(_ context.Context) error

Halt will attempt to gracefully shut down the server.

func (*Server) Run

func (gs *Server) Run(_ context.Context) 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