golem

module
v0.0.0-...-1ede896 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2025 License: MIT

README

go-joi

Build Status
Coverage Status
Go Report Card
Go Doc
Release

A schema description & validation library for Go, inspired by hapi/joi.


Contents


Getting started

  1. Install the package:
go get github.com/leandroluk/go-joi
  1. Import it in your project:
import "github.com/leandroluk/go-joi"
  1. Create and validate schemas:
schema := joi.Object(map[string]joi.Schema{
    "username": joi.String().Min(3).Max(20).Required(),
    "age":      joi.Number().Min(18).Required(),
    "email":    joi.String().Regex(regexp.MustCompile(`.+@.+\..+`)),
})

value := map[string]any{
    "username": "john_doe",
    "age":      25,
    "email":    "john@example.com",
}

parsed, errs := schema.Validate("user", value)
if len(errs) > 0 {
    fmt.Println("Validation failed:", errs)
} else {
    fmt.Println("Validation passed:", parsed)
}

Usage

  • Basic types: String, Number, Boolean, Object
  • Rules:
    • String: .Min(), .Max(), .Regex(), .Trim(), .Lowercase(), .Uppercase()
    • Number: .Min(), .Max(), .Integer(), .Positive(), .Negative()
    • Boolean: .True(), .False(), .Truthy(), .Falsy()
    • Object: .Min(), .Max(), .Length(), .Unknown()

Available Schemas

  • ✅ String
  • ✅ Number
  • ✅ Boolean
  • ✅ Object
  • ⬜ Array (coming soon)

Examples

String Validation
joi.String().Min(5).Max(10).Trim()
Number Validation
joi.Number().Integer().Positive()
Boolean Validation
joi.Boolean().Truthy("yes", "1").Falsy("no", "0")
Object Validation
joi.Object(map[string]joi.Schema{
    "id":   joi.Number().Required(),
    "name": joi.String().Min(3),
}).Unknown(false)

Implementation Status

  • String rules
  • Number rules
  • Boolean rules
  • Object rules
  • Array rules
  • Custom extensions

About the Project

This project was inspired by joi for Node.js and aims to bring a similar developer experience to Go.


Contributors

Thanks to all the people who contribute! [Contribute]


License

MIT License – see LICENSE file for details.

Directories

Path Synopsis
driver
examples
postgres command

Jump to

Keyboard shortcuts

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