server

package
v1.9.1 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2021 License: MIT Imports: 22 Imported by: 4

Documentation

Overview

Package server contains utilities for managing different kinds of servers. Currently supports HTTP & gRPC.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidTLSHost = errors.New("invalid tls host")

ErrInvalidTLSHost is the error given when an inbound TLS request does not match the server's host policy.

Functions

func DialGRPC added in v1.4.0

func DialGRPC(ctx context.Context, addr string, opts ...grpc.DialOption) (*grpc.ClientConn, error)

DialGRPC connects to a desired gRPC server, applying default options and registering interceptors.

func ServeGRPC

func ServeGRPC(ctx context.Context, opts ...GRPCOption) error

ServeGRPC starts a gRPC server listening on port 5000 configured using the provided options. This function blocks until the provided context is cancelled. On cancellation, the server is gracefully stopped.

func ServeHTTP

func ServeHTTP(ctx context.Context, opts ...HTTPOption) error

ServeHTTP starts the HTTP server. When the provided context is closed, the server is shut down.

Types

type GRPCOption

type GRPCOption func(c *grpcConfig)

The GRPCOption type is a function that modifies a field on the gRPC configuration.

func WithServerOptions

func WithServerOptions(opts ...grpc.ServerOption) GRPCOption

WithServerOptions configures the options to use when calling grpc.NewServer.

func WithService

func WithService(svc GRPCService) GRPCOption

WithService adds a GRPCService implementation whose Register method will be called once the server is started.

type GRPCService

type GRPCService interface {
	Register(svr *grpc.Server)
}

The GRPCService interface describes types that can be registered to a gRPC service. Each service implementation should have a Register method that registers the type to the gRPC server.

type HTTPOption

type HTTPOption func(c *httpConfig)

The HTTPOption type represents a server option that can be used to modify the HTTP server configuration.

func WithAllowedHosts

func WithAllowedHosts(hosts ...string) HTTPOption

WithAllowedHosts sets hosts that are allowed to make TLS requests.

func WithHandler

func WithHandler(r *mux.Router) HTTPOption

WithHandler sets the server's handler to the one provided.

func WithSecurity

func WithSecurity(flag bool) HTTPOption

WithSecurity enables/disables the server's SSL features.

func WithTLSCache

func WithTLSCache(dir string) HTTPOption

WithTLSCache determines the location on the filesystem that TLS certificates will be cached.

Jump to

Keyboard shortcuts

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