Giter VIP home page Giter VIP logo

go-verify's Introduction

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:

  • 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:

package yours

import (
	"fmt"

	"github.com/mkafonso/schema/pkg/validator"
)

func ValidateEmailExample() {
	input := "[email protected]"

	// 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.

go-verify's People

Contributors

mkafonso avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.