service

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2020 License: MIT Imports: 18 Imported by: 1

README

Go Report Card godoc license Coverage

service

A service package to serve grpc, grpc-gateway, and additional http handlers

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidHost error message
	ErrInvalidHost = errors.New("Host wasn't provided or is invalid")

	// ErrInvalidPort error message
	ErrInvalidPort = errors.New("Invalid port %d")

	// ErrAddingRootCA error message
	ErrAddingRootCA = errors.New("Unable to add Root CA to cert pool, invalid cert.")

	// ErrMissingPublicCert error message
	ErrMissingPublicCert = errors.New("Missing public cert. Fix by using: service.AddKeyPair or server.AddKeyPairFromFiles")

	// ErrMissingPrivateKey error message
	ErrMissingPrivateKey = errors.New("Missing private key. Fix by using: service.AddKeyPair or server.AddKeyPairFromFiles")

	// ErrAddKeyPairPublicCertIsNil error message
	ErrAddKeyPairPublicCertIsNil = errors.New("Unable to add key pair, public cert is nil")

	// ErrAddKeyPairPrivateKeyIsNil error message
	ErrAddKeyPairPrivateKeyIsNil = errors.New("Unable to add key pair, private key is nil")

	// ErrAddKeyPairFromFilePublicCertEmpty error message
	ErrAddKeyPairFromFilePublicCertEmpty = errors.New("Unable to add key pair from files, public cert is empty")

	// ErrAddKeyPairFromFilePublicCertNotFound error message
	ErrAddKeyPairFromFilePublicCertNotFound = errors.New("Unable to add key pair, public cert not found at %s")

	// ErrAddKeyPairPrivateKeyEmpty error message
	ErrAddKeyPairPrivateKeyEmpty = errors.New("Unable to add key pair, private key is nil")

	// ErrAddKeyPairFromFilePrivateKeyNotFound error message
	ErrAddKeyPairFromFilePrivateKeyNotFound = errors.New("Unable to add key pair, private key not found at %s")

	// ErrGatewayHandlerIsNil error message
	ErrGatewayHandlerIsNil = errors.New("Gateway entrypoint handler nil")
)

Functions

func ErrReplacer

func ErrReplacer(err error, replacers ...interface{}) error

ErrReplacer allows for static errors to have dynamic values

Types

type Grpc

type Grpc struct {
	MaxReceiveSize int
	MaxSendSize    int

	ServerOptions      []grpc.ServerOption
	UnaryInterceptors  []grpc.UnaryServerInterceptor
	StreamInterceptors []grpc.StreamServerInterceptor

	Server *grpc.Server
}

Grpc holds settings and server

func (*Grpc) AddOptions

func (g *Grpc) AddOptions(opts ...grpc.ServerOption)

AddOptions is an exposed method to append options

func (*Grpc) AddStreamInterceptors

func (g *Grpc) AddStreamInterceptors(interceptors ...grpc.StreamServerInterceptor)

AddStreamInterceptors is an exposed method to append stream interceptors

func (*Grpc) AddUnaryInterceptors

func (g *Grpc) AddUnaryInterceptors(interceptors ...grpc.UnaryServerInterceptor)

AddUnaryInterceptors is an exposed method to append unary interceptors

type Service

type Service struct {
	Port int

	CertPool   *x509.CertPool
	PublicCert []byte
	PrivateKey []byte

	Grpc *Grpc

	Mux *http.ServeMux

	Router *chi.Mux
	// contains filtered or unexported fields
}

Service holds the top level settings and references

func New

func New(port int) (*Service, error)

New initiates a new Service with default settings

func (*Service) AddGatewayHandler

func (s *Service) AddGatewayHandler(handler ...func(context.Context, *runtime.ServeMux, string, []grpc.DialOption) error) error

AddGatewayHandler allows for adding for http(s) fallbacks

func (*Service) AddHttpMiddlware

func (s *Service) AddHttpMiddlware(handler func(http.Handler) http.Handler)

AddHttpMiddlware allows for adding middleware to http(s) specifically

func (*Service) AddKeyPair

func (s *Service) AddKeyPair(publicCert, privateKey []byte) error

AddKeyPair allows for direct setting of cert/keys

func (*Service) AddKeyPairFromFiles

func (s *Service) AddKeyPairFromFiles(publicCertFile, privateKeyFile string) error

AddKeyPairFromFiles allows for setting cert/key from files

func (*Service) AppendCertsFromPEM

func (s *Service) AppendCertsFromPEM(rootCA []byte) error

AppendCertsFromPEM support direct setting of rootCA

func (*Service) EnableInsecure

func (s *Service) EnableInsecure()

EnableInsecure is a setter for enabling the insecure flag

func (*Service) GetCertificate

func (s *Service) GetCertificate() (tls.Certificate, error)

GetCertificate is a helper for pulling tls.Certificate from provided cert/key

func (*Service) GracefulShutdown

func (s *Service) GracefulShutdown(ctx context.Context) error

GracefulShutdown attempts to gracefully shutdown server given a context timeout

func (*Service) GrpcServer

func (s *Service) GrpcServer() *grpc.Server

GrpcServer creates and returns the server after applying ServerOptions

func (*Service) Serve

func (s *Service) Serve() error

Serve serves up everything that has been configured/defined

func (*Service) Shutdown

func (s *Service) Shutdown() error

Shutdown will handle an immediate shutdown without concern for any pending requests using GracefulShutdown is recommended

Directories

Path Synopsis
protos
Package protos is a reverse proxy.
Package protos is a reverse proxy.
Code generated for package swagger by go-bindata DO NOT EDIT.
Code generated for package swagger by go-bindata DO NOT EDIT.

Jump to

Keyboard shortcuts

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