gRPC Server
pkg/grpc/server runs a gRPC server as a SyncModule, pre-wired with grpc-ecosystem middleware for logging, recovery, and tracing.
Pass your service implementation directly via WithService. No separate module or DI wiring needed.
lakta.NewRuntime( config.NewModule( config.WithConfigDirs(".", "./config"), config.WithArgs(os.Args[1:]), ), tint.NewModule(), slog.NewModule(), otel.NewModule(), health.NewModule(), grpcserver.NewModule( grpcserver.WithService(&v1.MyService_ServiceDesc, NewServer()), ),)Implementing a service
Section titled “Implementing a service”type MyServer struct { v1.UnimplementedMyServiceServer}
func NewServer() *MyServer { return &MyServer{} }
func (s *MyServer) GetThing(ctx context.Context, req *pb.GetThingRequest) (*pb.GetThingResponse, error) { svc, err := lakta.Invoke[*MyService](ctx) if err != nil { return nil, err } return svc.GetThing(ctx, req.Id)}Embed Unimplemented*Server to satisfy the interface for any methods you haven’t implemented yet. Use lakta.Invoke[T](ctx) inside handlers to access DI — the request context carries the injector.
Middleware
Section titled “Middleware”The following middleware is applied automatically:
- Recovery — converts panics to gRPC
INTERNALerrors - Logging — structured request/response logging via slox
- OpenTelemetry — trace propagation (when otel is enabled)
Multi-instance
Section titled “Multi-instance”grpcserver.NewModule( grpcserver.WithName("internal"), grpcserver.WithService(&v1.InternalService_ServiceDesc, NewInternalServer()),),grpcserver.NewModule( grpcserver.WithName("public"), grpcserver.WithService(&v1.PublicService_ServiceDesc, NewPublicServer()),),Configuration Reference
Section titled “Configuration Reference”Config path: modules.grpc.server.<name>
host host specifies the address for the GRPC server to bind to
LAKTA_MODULES_GRPC_SERVER_<NAME>_HOST port port represents the port number on which the GRPC server listens
LAKTA_MODULES_GRPC_SERVER_<NAME>_PORT health_check healthCheck determines whether gRPC health checking is enabled or disabled
LAKTA_MODULES_GRPC_SERVER_<NAME>_HEALTH_CHECK Code-only options
Section titled “Code-only options”These options can only be set in Go code via With*() functions, not via config files or environment variables.
| Option | Type | Description |
|---|---|---|
WithService(...) | map[*grpc.ServiceDesc]any | adds service to the list of services to be registered (code-only) |