serve

package
v0.0.0-...-748ecea Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GRPC

func GRPC(log *slog.Logger, host string, port uint16, srv *grpc.Server) func(context.Context) error

GRPC starts gRPC server on addr, logged as service. It runs until failed or ctx.Done.

func GRPCGateWay

func GRPCGateWay(log *slog.Logger, host string, port uint16, cfg GateWayConfig) func(context.Context) error

GRPCGateWay starts HTTP-proxy server for gRPC serer, for using gRPC endpoints from WEB.

func HTTP

func HTTP(log *slog.Logger, host string, port uint16, handler http.Handler) func(context.Context) error

HTTP starts HTTP server on addr using handler logged as service. It runs until failed or ctx.Done.

func HandleMetrics

func HandleMetrics(mux *http.ServeMux, reg *prometheus.Registry)

HandleMetrics adds reg's prometheus handler on /metrics at mux.

func Metrics

func Metrics(log *slog.Logger, host string, port uint16, reg *prometheus.Registry) func(context.Context) error

Metrics starts HTTP server on addr path /metrics using reg as prometheus handler.

func Start

func Start(ctx context.Context, services ...func(context.Context) error) error

Start runs given services in parallel until either ctx.Done or any service exits, then it call cancel and wait until all services will exit.

Returns error of first service which returned non-nil error, if any.

Types

type GateWayConfig

type GateWayConfig struct {
	FS             embed.FS
	Spec           string
	GRPCServerPort uint16
	Reg            *prometheus.Registry
	Namespace      string
	GRPCGWPattern  string                                                           // Pattern for http.ServeMux to serve grpc-gateway.
	DocsUIPattern  string                                                           // Pattern for http.ServeMux to serve Swagger UI.
	Register       func(context.Context, *runtime.ServeMux, *grpc.ClientConn) error // Register gRPC server.
	DevMode        bool
}

GateWayConfig is config for building gRPC-Gateway proxy for WEB clients.

Jump to

Keyboard shortcuts

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