protovalidate

package
v2.26.3 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2024 License: MIT Imports: 6 Imported by: 0

README

Proto-Validate

Proto-Validate is a middleware for Kratos.

The protovalidate uses the protovalidate-go library to validate the request messages of the gRPC service.

Usage Example

package main

import (
	"log"

	"github.com/bufbuild/protovalidate-go"
	"github.com/go-kratos/kratos/v2"
	"github.com/go-kratos/kratos/v2/transport/http"
	
	middlewareprotovalidate "github.com/go-kratos-ecosystem/components/v2/middleware/protovalidate"
)

func main() {
	validator, err := protovalidate.New(
		protovalidate.WithFailFast(true),
	)
	if err != nil {
		log.Fatal(err)
	}

	app := kratos.New(
		http.NewServer(
			http.Address(":8000"),
			middlewareprotovalidate.Server(
				middlewareprotovalidate.Validator(validator),
			),
		),
	)

	app.Run()
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Server

func Server(opts ...Option) middleware.Middleware

Types

type Option

type Option func(*options)

func Handler

func Handler(handler func(ctx context.Context, req any, err error) (any, error)) Option

func Validator

func Validator(validator *protovalidate.Validator) Option

Jump to

Keyboard shortcuts

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