Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

protovalidate: support new protovalidate-go Validator interface #746

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

zchee
Copy link

@zchee zchee commented Feb 3, 2025

Changes

protovalidate: support new protovalidate-go Validator interface.

Verification

protovalidate-go v0.9 release said:

protovalidate.Validator is now an intkerface and not a struct. Pointers of type *protovalidate.Validator should be changed to protovalidate.Validator values instead.

@zchee zchee force-pushed the support-protovalidate-go-0.9 branch 2 times, most recently from 21dd301 to 8cd57e5 Compare February 3, 2025 12:32
@zchee zchee force-pushed the support-protovalidate-go-0.9 branch from 8cd57e5 to d89418e Compare February 3, 2025 12:39
@zchee
Copy link
Author

zchee commented Feb 3, 2025

Why make all have the below diff?

diff --git a/README.md b/README.md
index 8c4ac16..c923991 100644
--- a/README.md
+++ b/README.md
@@ -17,22 +17,22 @@ ## Middleware
 Additional great feature of interceptors is the fact we can chain those. For example below you can find example server side chain of interceptors with full observabiliy correlation, auth and panic recovery:
 
 ```go mdox-exec="sed -n '136,151p' examples/server/main.go"
-	grpcSrv := grpc.NewServer(
-		grpc.ChainUnaryInterceptor(
-			// Order matters e.g. tracing interceptor have to create span first for the later exemplars to work.
-			otelgrpc.UnaryServerInterceptor(),
-			srvMetrics.UnaryServerInterceptor(grpcprom.WithExemplarFromContext(exemplarFromContext)),
-			logging.UnaryServerInterceptor(interceptorLogger(rpcLogger), logging.WithFieldsFromContext(logTraceID)),
-			selector.UnaryServerInterceptor(auth.UnaryServerInterceptor(authFn), selector.MatchFunc(allButHealthZ)),
-			recovery.UnaryServerInterceptor(recovery.WithRecoveryHandler(grpcPanicRecoveryHandler)),
-		),
-		grpc.ChainStreamInterceptor(
-			otelgrpc.StreamServerInterceptor(),
-			srvMetrics.StreamServerInterceptor(grpcprom.WithExemplarFromContext(exemplarFromContext)),
-			logging.StreamServerInterceptor(interceptorLogger(rpcLogger), logging.WithFieldsFromContext(logTraceID)),
-			selector.StreamServerInterceptor(auth.StreamServerInterceptor(authFn), selector.MatchFunc(allButHealthZ)),
-			recovery.StreamServerInterceptor(recovery.WithRecoveryHandler(grpcPanicRecoveryHandler)),
-		),
+	)
+	t := &testpb.TestPingService{}
+	testpb.RegisterTestServiceServer(grpcSrv, t)
+	srvMetrics.InitializeMetrics(grpcSrv)
+
+	g := &run.Group{}
+	g.Add(func() error {
+		l, err := net.Listen("tcp", grpcAddr)
+		if err != nil {
+			return err
+		}
+		logger.Info("starting gRPC server", "addr", l.Addr().String())
+		return grpcSrv.Serve(l)
+	}, func(err error) {
+		grpcSrv.GracefulStop()
+		grpcSrv.Stop()

This pattern offers clean and explicit shared functionality for all your gRPC methods. Full, buildable examples can be found in examples directory.

@charlieparkes-Q
Copy link

charlieparkes-Q commented Feb 3, 2025

Would love to get this version upgrade merged as it's blocking package upgrades on our projects. protovalidate-go v0.8 and v0.9 broke compatibility, and was fixed with v0.9.1. bufbuild/protovalidate-go#180 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants