grpc

package
v1.15.2 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BearerAuth

func BearerAuth(check TokenFunc, public ...string) ggrpc.UnaryServerInterceptor

BearerAuth returns a unary interceptor that requires "authorization: Bearer <token>" metadata on every call except the methods listed in public (full names, such as "/greeter.Greeter/Ping") and the health service. A missing or rejected token answers codes.Unauthenticated.

func Token

func Token(ctx context.Context) string

Token returns the bearer token the call was authorised with, if any.

Types

type Config

type Config struct {
	// Addr is where the server listens. Default GRPC_ADDR, then ":50051".
	Addr string
	// Register adds your services to the server. Called once, before it starts.
	Register func(s *ggrpc.Server)
	// Reflection exposes the service list to tools like grpcurl. Nil means on
	// outside production (APP_ENV != "production"); GRPC_REFLECTION overrides.
	Reflection *bool
	// Unary and Stream interceptors run after the built-in recovery and
	// logging ones, in order.
	Unary  []ggrpc.UnaryServerInterceptor
	Stream []ggrpc.StreamServerInterceptor
	// Options are passed to grpc.NewServer as they are (TLS credentials,
	// message size limits, keepalive).
	Options []ggrpc.ServerOption
	// ShutdownTimeout bounds the graceful stop; after it, open calls are
	// cancelled. Default 10s.
	ShutdownTimeout time.Duration
	// Logger receives one line per call. Default log.Printf; set Quiet to
	// turn call logs off.
	Logger func(format string, args ...any)
	Quiet  bool
}

Config configures the gRPC server.

type Plugin

type Plugin struct {
	nimbus.BasePlugin
	// contains filtered or unexported fields
}

Plugin runs a gRPC server alongside the HTTP server.

func New

func New(cfg Config) *Plugin

New creates the gRPC plugin. Settings left empty come from the environment, then from the defaults above.

func (*Plugin) Addr

func (p *Plugin) Addr() net.Addr

Addr reports where the server is listening once it has started (useful with Addr ":0" in tests).

func (*Plugin) Name

func (p *Plugin) Name() string

Name implements nimbus.Plugin.

func (*Plugin) Server

func (p *Plugin) Server() *ggrpc.Server

Server builds the gRPC server with the built-in interceptors, health and reflection, and your services. Start calls it; tests can call it directly.

func (*Plugin) Shutdown

func (p *Plugin) Shutdown() error

Shutdown implements nimbus.HasShutdown: health turns NOT_SERVING, open calls get ShutdownTimeout to finish, then the rest are cancelled.

func (*Plugin) Start

func (p *Plugin) Start(*nimbus.App) error

Start implements nimbus.HasStart: it listens and serves in the background.

func (*Plugin) Version

func (p *Plugin) Version() string

Version implements nimbus.Plugin.

type TokenFunc

type TokenFunc func(ctx context.Context, token string) (context.Context, error)

TokenFunc checks a bearer token and returns the context the handler should run with (for example with the user attached), or an error.

Jump to

Keyboard shortcuts

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