Skip to content

A gRPC Go middleware for validating messages via bufbuild/protovalidate following Google's API Improvement Proposals AIP-193

License

Notifications You must be signed in to change notification settings

rudeigerc/go-grpc-protovalidate

Repository files navigation

go-grpc-protovalidate

Caution

WORK IN PROGRESS

A gRPC Go middleware for validating messages via bufbuild/protovalidate following Google's API Improvement Proposals AIP-193.

Installation

go get github.com/rudeigerc/go-grpc-protovalidate

Usage

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)),
		),
	)
}

References

License

Apache 2.0

About

A gRPC Go middleware for validating messages via bufbuild/protovalidate following Google's API Improvement Proposals AIP-193

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published