Skip to content

Go package for Struct Validation - Validate the data coming from a JSON into a Struct, without having to decode it beforehand!

License

Notifications You must be signed in to change notification settings

budnieswski/validate-struct

Repository files navigation

Validate Struct

GitHub tag (latest by date) Coveralls Go Report Card GoDoc GitHub go.mod Go version License

Contents

Install

go get github.com/budnieswski/validate-struct

Example

package main

import (
	"encoding/json"
	"fmt"

	ValidateStruct "github.com/budnieswski/validate-struct"
)

type User struct {
	ID     uint64 `json:"id" validate:"required,min=2,max=4"`
	Name   string `json:"name" validate:"required,min=3"`
	Status bool   `json:"status"`
}

func main() {
	input := []byte(`
		{
			"id": 12,
			"name": "Mr Dummy",
			"status": true
		}
	`)

	valid := ValidateStruct.Validate(input, User{})

	if len(valid) > 0 {
		fmt.Println("Validation failed")
		resp, _ := json.Marshal(valid)
		fmt.Println(string(resp))
	}
}

Goals

  • Create validate tests
  • Create rule tests
  • Standardize validate error return
  • Create Github templates
    • Contributing
    • Issue
    • Pull request
  • Create Github workflows
    • Tests
    • Coverage
    • CI
  • Create doc.go
  • Make validate benchmarks
  • Improve performance
  • Create a way for the user add custom rules

About

Go package for Struct Validation - Validate the data coming from a JSON into a Struct, without having to decode it beforehand!

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages