duplex

package
v0.17.3 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2024 License: Apache-2.0 Imports: 11 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Duplex

type Duplex struct {
	Server      *grpc.Server
	MUX         *runtime.ServeMux
	Loopback    string
	Host        string
	Port        int
	DialOptions []grpc.DialOption
}

Duplex is a wrapper for the gRPC server, gRPC HTTP Gateway MUX and options.

func New

func New(port int, opts ...interface{}) *Duplex

New creates a Duplex gRPC server / gRPC HTTP Gateway. New takes in options for `grpc.NewServer`, typed `grpc.ServerOption`, and `runtime.NewServeMux`, typed `runtime.ServeMuxOption`. Unknown opts will cause a panic.

func (*Duplex) ListenAndServe

func (d *Duplex) ListenAndServe(_ context.Context) error

ListenAndServe starts both the gRPC server and HTTP Gateway MUX. Note: This call is blocking.

func (*Duplex) RegisterHandler

func (d *Duplex) RegisterHandler(ctx context.Context, fn RegisterHandlerFromEndpointFn) error

RegisterHandler is a helper registration handler to call the passed in `RegisterHandlerFromEndpointFn` with the correct options after `d.Server` has been registered with the implementation. Use like: ```go

pb.Register<Type>Server(d.Server, impl.New<TypeImpl>())
if err := d.RegisterHandler(ctx, pb.Register<Type>HandlerFromEndpoint); err != nil {
	log.Panicf("Failed to register gateway endpoint: %v", err)
}

```

func (*Duplex) RegisterListenAndServeMetrics added in v0.5.0

func (d *Duplex) RegisterListenAndServeMetrics(port int, enablePprof bool)

RegisterListenAndServe initializes Prometheus metrics and starts a HTTP /metrics endpoint for exporting Prometheus metrics in the background. Call this *after* all services have been registered.

func (*Duplex) Serve added in v0.11.0

func (d *Duplex) Serve(_ context.Context, listener net.Listener) error

ListenAndServe starts both the gRPC server and HTTP Gateway MUX on the given listener. Note: This call is blocking. #nosec G114 -- used only for testing tls.

type RegisterHandlerFromEndpointFn

type RegisterHandlerFromEndpointFn func(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) error

Jump to

Keyboard shortcuts

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