go_grpc_protovalidate

package module
v0.0.0-...-942d59b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 18, 2024 License: Apache-2.0 Imports: 8 Imported by: 1

README

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StreamServerInterceptor

func StreamServerInterceptor(opts ...Option) grpc.StreamServerInterceptor

func UnaryServerInterceptor

func UnaryServerInterceptor(opts ...Option) grpc.UnaryServerInterceptor

Types

type Option

type Option func(*options)

func WithValidator

func WithValidator(validator *protovalidate.Validator) Option

Directories

Path Synopsis
examples module

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL