https://github.com/mkafonso/schema
A Golang schema validation toolkit that takes inspiration from https://zod.dev/ - because who doesn't love a good source of inspiration? 🎉
https://github.com/mkafonso/schema
go go-schema go-verify golang open-source string-validation struct-validator toolkit validation zod
Last synced: 14 days ago
JSON representation
A Golang schema validation toolkit that takes inspiration from https://zod.dev/ - because who doesn't love a good source of inspiration? 🎉
- Host: GitHub
- URL: https://github.com/mkafonso/schema
- Owner: mkafonso
- License: mit
- Created: 2023-09-25T01:00:04.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-11-22T01:47:18.000Z (about 1 year ago)
- Last Synced: 2025-04-11T23:52:56.799Z (10 months ago)
- Topics: go, go-schema, go-verify, golang, open-source, string-validation, struct-validator, toolkit, validation, zod
- Language: Go
- Homepage:
- Size: 68.4 KB
- Stars: 37
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
## Example

# Schema - A Go Validation Library
This is an open-source schema validation toolkit inspired by zod.dev. It provides a simple and expressive API for validating strings, numbers, struct, ... with various constraints. Schema is designed to be easy to use, extensible, and suitable for a wide range of applications.
Feel free to use and modify it for any purpose. If you have any suggestions for improvement, please don't hesitate to reach out. Thank you!
---
Features include:
- String Validation: Min/Max length, email format, and more.
- Number Validation: Min/Max value, integer check, positive/negative, even/odd, divisibility, and more.
- Custom Error Messages: Provide custom error messages for failed validations.
- Composability: Combine multiple validations easily.
- Extensible: Easy to add custom validation logic.
---
## Installation
To install this package, use `go get`:
go get github.com/mkafonso/schema
---
## Get started:
- Install schema with [one line of code](#installation)
- Check out the API Documentation https://pkg.go.dev/github.com/mkafonso/schema
## [`String Validation`](https://pkg.go.dev/github.com/mkafonso/schema/string "API documentation") package
- Minimum Length: Ensure the string has a minimum length.
- Maximum Length: Ensure the string does not exceed a maximum length.
- Email Format: Validate the string as an email format.
See it in action:
```go
package yours
import (
"fmt"
"github.com/mkafonso/schema/pkg/validator"
)
func ValidateEmailExample() {
input := "mkafonso.dev@gmail.com"
// Defining a validation schema
stringValidator := validator.NewStringValidator().
MinLength(5, "A string deve ter no mÃnimo 5 caracteres"). // Sets minimum length constraint
MaxLength(50, "A string deve ter no máximo 50 caracteres"). // Sets maximum length constraint
IsEmail("Formato de email inválido") // Validates as an email format
// Validating the input
result := stringValidator.Validate(input)
// Handling validation result
if result.IsValid {
fmt.Println("Validation successful!") // Message for successful validation
} else {
fmt.Println("Validation error:", result.Errors) // Printing validation errors
}
}
```
---
# License
This project is licensed under the terms of the MIT license.