Documentation
¶
Overview ¶
Package grpc provides a lagodev-flavoured gRPC server: Laravel-style graceful shutdown, structured logging, panic recovery, and an optional JWT auth interceptor that surfaces `auth_user_id` and `auth_role` on the request context — the same contract the lagodev web middleware uses.
The adapter is a separate Go module so the core lagodev module does not depend on google.golang.org/grpc:
go get github.com/devituz/lagodev/adapters/grpc@latest
Usage:
srv := lagogrpc.New(lagogrpc.Options{
Addr: ":50051",
Auth: lagogrpc.AuthFromManager(authMgr),
Logger: log.Default(),
})
mypb.RegisterMyServiceServer(srv.GRPC(), impl)
if err := srv.Run(ctx); err != nil { ... }
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AuthFunc ¶
AuthFunc resolves the metadata-carried token to a claims-bearing context. Returning a non-nil error short-circuits the RPC with codes.Unauthenticated.
func AuthFromManager ¶
AuthFromManager builds an AuthFunc using a lagodev/auth Manager. On success it populates "auth_user_id" and "auth_role" in the context so service handlers can pull them via FromContext.
type Options ¶
type Options struct {
// Addr to listen on (e.g. ":50051").
Addr string
// Logger receives access / panic logs. Default: log.Default().
Logger *log.Logger
// ShutdownTimeout caps GracefulStop. Default 10s.
ShutdownTimeout time.Duration
// Auth optionally enforces a JWT on every RPC. When non-nil it is
// installed as a unary interceptor; pair with AuthFromManager to
// reuse the lagodev/auth manager you already configured for HTTP.
Auth AuthFunc
// Recovery toggles panic recovery (default true).
Recovery bool
// Logging toggles access logging (default true).
Logging bool
// AdditionalUnaryInterceptors are appended after Recovery/Auth/
// Logging so call sites can add tracing or rate-limit middleware.
AdditionalUnaryInterceptors []grpc.UnaryServerInterceptor
// AdditionalStreamInterceptors are appended after Recovery/Auth/
// Logging in the streaming chain.
AdditionalStreamInterceptors []grpc.StreamServerInterceptor
// AdditionalOptions are appended to the underlying grpc.Server
// construction (e.g. TLS credentials).
AdditionalOptions []grpc.ServerOption
}
Options configures Server.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is the lagodev-flavoured gRPC server.
func New ¶
New constructs a Server. Interceptors are installed in the order: Recovery → Auth → Logging → user-supplied.