Caution
WORK IN PROGRESS
A gRPC Go middleware for validating messages via bufbuild/protovalidate following Google's API Improvement Proposals AIP-193.
go get github.com/rudeigerc/go-grpc-protovalidate
package main
import (
"log"
"github.com/bufbuild/protovalidate-go"
go_grpc_protovalidate "github.com/rudeigerc/go-grpc-protovalidate"
"google.golang.org/grpc"
)
func main() {
validator, err := protovalidate.New()
if err != nil {
log.Fatalf("failed to create validator: %v", err)
}
s := grpc.NewServer(
grpc.ChainUnaryInterceptor(
go_grpc_protovalidate.UnaryServerInterceptor(go_grpc_protovalidate.WithValidator(validator)),
),
grpc.ChainStreamInterceptor(
go_grpc_protovalidate.StreamServerInterceptor(go_grpc_protovalidate.WithValidator(validator)),
),
)
}
- bufbuild/protovalidate
- grpc-ecosystem/go-grpc-middleware/interceptors/protovalidate
- Errors | Cloud API Design Guide | Google Cloud
- AIP-193: Errors
Apache 2.0