gody

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2020 License: MIT Imports: 4 Imported by: 0

README

gody

🎈 A lightweight struct validator for Go

Mentioned in Awesome Go GoDoc Go Report Card Build Status Coverage Status GitHub release (latest by date)

Quick start

package main

import (
	"log"

	"github.com/guiferpa/gody"
	"github.com/guiferpa/gody/rule"
)

type Body struct {
	Text string `json:"text" validate:"not_empty"`
}

func main() {
	b := Body{}

	if valid, err := gody.Validate(b, nil); err != nil {
		if !valid {
			log.Println("body didn't validate:", err)
		}

		switch err.(type) {
		case *rule.ErrNotEmpty:
			log.Println(err)
		}
	}
}
Kinds of validation

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Validate

func Validate(b interface{}, customRules []rule.Rule) (bool, error)

Validate contains the entrypoint to validation of struct input

Types

type ErrInvalidBody

type ErrInvalidBody struct {
	Kind reflect.Kind
}

ErrInvalidBody represents all invalid body report

func (*ErrInvalidBody) Error

func (e *ErrInvalidBody) Error() string

type ErrInvalidTag

type ErrInvalidTag struct {
	Format string
}

ErrInvalidTag represents all invalid tag report

func (*ErrInvalidTag) Error

func (e *ErrInvalidTag) Error() string

type Field

type Field struct {
	Name  string
	Value string
	Tags  map[string]string
}

Field is a struct to represents the domain about a field inner gody lib

func Serialize

func Serialize(b interface{}) ([]Field, error)

Serialize is a func to serialize/parse all content about the struct input

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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