{"id":14628474,"url":"https://github.com/connectrpc/validate-go","last_synced_at":"2025-12-30T00:03:06.099Z","repository":{"id":192983319,"uuid":"678840373","full_name":"connectrpc/validate-go","owner":"connectrpc","description":"Flexible, efficient request validation for Connect.","archived":false,"fork":false,"pushed_at":"2025-09-27T17:28:03.000Z","size":78,"stargazers_count":95,"open_issues_count":0,"forks_count":11,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-09-27T18:08:04.015Z","etag":null,"topics":["connectrpc","golang","protobuf","protovalidate","rpc","validation"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/connectrpc.com/validate","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/connectrpc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":"MAINTAINERS.md","copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-08-15T14:01:04.000Z","updated_at":"2025-09-27T17:27:12.000Z","dependencies_parsed_at":"2023-09-06T08:40:24.350Z","dependency_job_id":"de684643-f0eb-4e3b-8154-58e9df888396","html_url":"https://github.com/connectrpc/validate-go","commit_stats":{"total_commits":18,"total_committers":8,"mean_commits":2.25,"dds":0.7777777777777778,"last_synced_commit":"1aab3dbf631cd4e925094a370a7a163839c7f2f0"},"previous_names":["connectrpc/validate-go"],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/connectrpc/validate-go","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/connectrpc%2Fvalidate-go","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/connectrpc%2Fvalidate-go/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/connectrpc%2Fvalidate-go/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/connectrpc%2Fvalidate-go/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/connectrpc","download_url":"https://codeload.github.com/connectrpc/validate-go/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/connectrpc%2Fvalidate-go/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28122312,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-12-29T02:00:07.021Z","response_time":58,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["connectrpc","golang","protobuf","protovalidate","rpc","validation"],"created_at":"2024-09-09T09:01:44.982Z","updated_at":"2025-12-30T00:03:06.086Z","avatar_url":"https://github.com/connectrpc.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"# Validate\n\n[![Build](https://github.com/connectrpc/validate-go/actions/workflows/ci.yaml/badge.svg?branch=main)](https://github.com/connectrpc/validate-go/actions/workflows/ci.yaml)\n[![Report Card](https://goreportcard.com/badge/connectrpc.com/validate)](https://goreportcard.com/report/connectrpc.com/validate)\n[![GoDoc](https://pkg.go.dev/badge/connectrpc.com/validate.svg)](https://pkg.go.dev/connectrpc.com/validate)\n\n`connectrpc.com/validate` provides a [Connect][connect-go] interceptor that\ntakes the tedium out of data validation. Rather than hand-writing repetitive\ndocumentation and code \u0026mdash; verifying that `User.email` is valid, or that\n`User.age` falls within reasonable bounds \u0026mdash; you can instead encode those\nconstraints into your Protobuf schemas and automatically enforce them at\nruntime.\n\nUnder the hood, this package is powered by [protovalidate][protovalidate-go]\nand the [Common Expression Language][cel-spec]. Together, they make validation\nflexible, efficient, and consistent across languages _without_ additional code\ngeneration.\n\n## Installation\n\n```bash\ngo get connectrpc.com/validate\n```\n\n## A small example\n\nCurious what all this looks like in practice? First, let's define a schema for\nour user service:\n\n```protobuf\nsyntax = \"proto3\";\n\npackage example.user.v1;\n\nimport \"buf/validate/validate.proto\";\nimport \"google/protobuf/timestamp.proto\";\n\nmessage User {\n  // Simple constraints, like checking that an email address is valid, are\n  // predefined.\n  string email = 1 [(buf.validate.field).string.email = true];\n\n  // For more complex use cases, like comparing fields against each other, we\n  // can write a CEL expression.\n  google.protobuf.Timestamp birth_date = 2;\n  google.protobuf.Timestamp signup_date = 3;\n\n  option (buf.validate.message).cel = {\n    id: \"user.signup_date\",\n    message: \"signup date must be on or after birth date\",\n    expression: \"this.signup_date \u003e= this.birth_date\"\n  };\n}\n\nmessage CreateUserRequest {\n  User user = 1;\n}\n\nmessage CreateUserResponse {\n  User user = 1;\n}\n\nservice UserService {\n  rpc CreateUser(CreateUserRequest) returns (CreateUserResponse) {}\n}\n```\n\nNotice that simple constraints, like checking email addresses, are short and\ndeclarative. When we need a more elaborate constraint, we can write a custom\nCEL expression, customize the error message, and much more. (See [the\nmain protovalidate repository][protovalidate] for more examples.)\n\nAfter implementing `UserService`, we can add a validating interceptor with just\none option:\n\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"log\"\n\t\"net/http\"\n\n\t\"connectrpc.com/connect\"\n\t\"connectrpc.com/validate\"\n\tuserv1 \"connectrpc.com/validate/internal/gen/example/user/v1\"\n\t\"connectrpc.com/validate/internal/gen/validate/example/v1/userv1connect\"\n)\n\nfunc main() {\n\tmux := http.NewServeMux()\n\tmux.Handle(userv1connect.NewUserServiceHandler(\n\t\t\u0026userv1connect.UnimplementedUserServiceHandler{},\n\t\tconnect.WithInterceptors(validate.NewInterceptor()),\n\t))\n\n\thttp.ListenAndServe(\"localhost:8080\", mux)\n}\n```\n\nWith the `validate.Interceptor` applied, our `UserService` implementation can\nassume that all requests (and optionally responses) have already been\nvalidated \u0026mdash; no need for hand-written boilerplate!\n\n## FAQ\n\n### Does this interceptor work with Connect clients?\n\nYes: it validates request messages before sending them to the server, and optionally\nresponses when they are received. But unless you're _sure_ that your clients always have\nan up-to-date schema, it's better to let the server handle validation.\n\n### How do clients know which fields are invalid?\n\nIf the message fails validation, the interceptor returns an error coded\nwith `connect.CodeInvalidArgument`. It also adds a [detailed representation of the\nvalidation error(s)][violations] as an [error detail][connect-error-detail].\n\n### How should schemas import protovalidate's options?\n\nBecause this interceptor uses [protovalidate][protovalidate-go], it doesn't\nneed any generated code for validation. However, any Protobuf schemas with\nconstraints must import [`buf/validate/validate.proto`][validate.proto]. It's\neasiest to import this file directly from the [Buf Schema\nRegistry][bsr]: this repository contains an [example\nschema](internal/proto/example/user/v1/user.proto) with constraints,\n[buf.yaml](internal/proto/buf.yaml) and [buf.gen.yaml](buf.gen.yaml)\nconfiguration files, and `make generate` [recipe](Makefile).\n\n### Does the interceptor validate responses?\n\nBy default, on both clients and servers, the interceptor only validates requests.\nIf you'd additionally like to validate responses, use the `WithValidateResponses`\noption when constructing your `Interceptor`.\n\n## Ecosystem\n\n* [connect-go]: the Connect runtime\n* [protovalidate-go]: the underlying Protobuf validation library\n* [protovalidate]: schemas and documentation for the constraint language\n* [CEL][cel-spec]: the Common Expression Language\n\n## Status: Unstable\n\nThis module is unstable. Expect breaking changes as we iterate toward a stable\nrelease.\n\nIt supports:\n\n* The two most recent major releases of Go. Keep in mind that [only the last\n  two releases receive security patches][go-support-policy].\n* [APIv2] of Protocol Buffers in Go (`google.golang.org/protobuf`).\n\nWithin those parameters, this project follows semantic versioning. Once we tag\na stable release, we will _not_ make breaking changes without incrementing the\nmajor version.\n\n\n## License\n\nOffered under the [Apache 2 license](LICENSE).\n\n[APIv2]: https://blog.golang.org/protobuf-apiv2\n[bsr]: https://buf.build\n[cel-spec]: https://github.com/google/cel-spec\n[connect-error-detail]: https://pkg.go.dev/connectrpc.com/connect#ErrorDetail\n[connect-go]: https://github.com/connectrpc/connect-go\n[go-support-policy]: https://golang.org/doc/devel/release#policy\n[protovalidate-go]: https://github.com/bufbuild/protovalidate-go\n[protovalidate]: https://github.com/bufbuild/protovalidate\n[validate.proto]: https://github.com/bufbuild/protovalidate/blob/main/proto/protovalidate/buf/validate/validate.proto\n[violations]: https://pkg.go.dev/buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go/buf/validate#Violations\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fconnectrpc%2Fvalidate-go","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fconnectrpc%2Fvalidate-go","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fconnectrpc%2Fvalidate-go/lists"}