{"id":36531297,"url":"https://github.com/antipitch/orwell","last_synced_at":"2026-01-12T03:01:36.971Z","repository":{"id":64304847,"uuid":"120335003","full_name":"Antipitch/orwell","owner":"Antipitch","description":"Orwell is a validator package for the Go programming language.","archived":false,"fork":false,"pushed_at":"2019-05-10T12:11:40.000Z","size":38,"stargazers_count":1,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-06-20T19:19:06.198Z","etag":null,"topics":["cross","dependant","field","fields","go","golang","package","structs","validation","validator"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Antipitch.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-02-05T17:03:01.000Z","updated_at":"2019-05-10T12:11:41.000Z","dependencies_parsed_at":"2023-01-15T10:15:53.112Z","dependency_job_id":null,"html_url":"https://github.com/Antipitch/orwell","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/Antipitch/orwell","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Antipitch%2Forwell","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Antipitch%2Forwell/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Antipitch%2Forwell/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Antipitch%2Forwell/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Antipitch","download_url":"https://codeload.github.com/Antipitch/orwell/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Antipitch%2Forwell/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28332841,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-12T00:36:25.062Z","status":"online","status_checked_at":"2026-01-12T02:00:08.677Z","response_time":98,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cross","dependant","field","fields","go","golang","package","structs","validation","validator"],"created_at":"2026-01-12T03:01:19.583Z","updated_at":"2026-01-12T03:01:36.959Z","avatar_url":"https://github.com/Antipitch.png","language":"Go","readme":"# Orwell\nOrwell is a validator package for the Go programming language.\n\n## Features\n- Quick and simple to use\n- Easy to extend with custom validation rules\n- Some of the most common validation rules baked in\n- Many cross-field validation rules (e.g. dependant struct fields)\n- Pure Go, no tags\n- No third party dependencies\n- Avoids complex regexes and reflection whenever possible\n\n\n## Usage\n### Simple data validation\nGet a new validator instance:\n````\nimport (\n\t\"github.com/Antipitch/orwell\"\n)\n\nv := orwell.NewValidator()\n````\n\nValidate something:\n````\ni := 42\n\nerr := v.Validate(i, v.Required())\n\nif err != nil {\n    log.Print(err.Error())\n}\n````\n\nAdd more Rules:\n````\nerr := v.Validate(i, v.Required(), v.Max(42), v.DivBy(21))\n````\n\nRules after failing rules wil not be applied:\n````\n// v.DivBy() will not be called\nerr := v.Validate(i, v.Required(), v.Max(41), v.DivBy(20))\n````\n\nNil or empty values are always valid except for the Required(), NotNil(), NotEmpty() and X-Rules:\n````\nvar (\n    i int\n    err error\n)\n\n// valid\nerr = v.Validate(i, v.Min(42))\n\n// not valid\nerr = v.Validate(i, v.NotEmpty(), v.Min(42))\n\ni = 41\n\n// not valid\nerr = v.Validate(i, v.NotEmpty(), v.Min(42))\n````\n\n### Struct Validation\nUse pointers both to the struct itself and to the fields to validate (fields passed as arguments to X-rules don't have to be pointers).\n````\ns := {\n    StringField: \"somestring\",\n    IntField: 1000,\n    StructField: {\n        ChildStringFiled: \"\",\n        ChildIntField: 0\n    } \n}\n\n// will return orwell.IterableError interface (s.Intfield is not valid)\nerr := v.ValidateStruct(\u0026s,\n    v.FieldRules(\u0026s.StringField, v.Required()),\n    v.FieldRules(\u0026s.StructField.ChildIntField, v.XLt(s.IntField, 1000))\n)\n````\n### Error handling\nOrwell exports three error interfaces: InternalError, IterableError and FieldableError (all of them implement Go's error interface).\n\nOrwell's Validate method will -for now- return a standard Go error, nothing special here. The ValidateStruct method will either return an InternalError or an IterableError. Proceed according to your needs with type assertion:\n````\nerr := v.ValidateStruct(\n    // validate some struct\n)\n\nif err != nil {\n    // don't react specifically, maybe log\n    log.Print(err.Error())\n\n    // internal error\n    internalError, ok := err.(orwell.InternalError)\n    if ok {\n        // do something with internal error\n    }\n\n    // iterable error\n    iterableError, ok := err.(orwell.IterableError)\n    if ok {\n        l := iterableError.Len()\n        for i := 0; i \u003c l; i++ {\n            if fe, ok := iterableError.ValueAt(i).(orwell.FieldableError); ok {\n                f := fe.FieldName\n                j := fe.JSONName\n                e := fe.Error()\n            }\n        }\n    }\n}\n````\n\n## Rules\n### Simple rules\n- `DivBy(arg int)` Must be dividable by arg\n- `In(args ...interface{})` Must be equal to one of args\n- `Email(arg bool)` Must be RFC 5322 compliant address (uses net/mail.ParseAddress and optionally net.LookupMX)\n- `LengthMax(arg int)` Must be of length not greater than arg\n- `LengthMin(arg int)` Must be of length not less than arg\n- `Max(arg int)` Must not be greater than arg\n- `Min(arg int)` Must not be lower than arg\n- `Match(arg string)` Must match regular expression described by arg\n- `NotNil()` Must not be nil\n- `Required()` Must neither be nil nor empty\n### X-Rules\n- `XAnd(arg interface{})` Required when arg is neither nil nor empty\n- `XAndOr(arg interface{}, args ...interface{})` Required when arg is neither nil nor empty and all args are nil or empty\n- `XGt(arg1 interface{}, arg2 int)` Required when arg1 is greater than arg2\n- `XGtEql(arg1 interface{}, arg2 int, arg3 interface{}, arg4 interface{})` Required when arg1 is greater than arg2 and arg3 is equal to arg4\n- `XGtEqlOr(arg1 interface{}, arg2 int, arg3 interface{}, arg4 interface{}, args ...interface{})` Required when arg1 is greater than arg2, arg3 is equal to arg4 and all args are nil or empty\n- `XGtAndOr(arg1 interface{}, arg2 int, arg3 interface{}, args ...interface{})` Required when arg1 is greater than arg2, arg3 is neither nil nor empty and all args are nil or empty\n- `XGtOr(arg1 interface{}, arg2 int, args ...interface{})` Required when arg1 is greater than arg2 and all args are nil or empty\n- `XLt(arg1 interface{}, arg2 int)` Required when arg1 is lower than arg2\n- `XLtOr(arg1 interface{}, arg2 int, args ...interface{})` Required when arg1 is lower than arg2 and all args are nil or empty\n- `XNor(args ...interface{})` Must be nil or empty when all args are nil or empty\n- `XNot(arg interface{})` Must be nil or empty when arg is neither nil nor empty\n- `XOr(args ...interface{})` Required when all args are nil or empty\n\nOrwell is a new project and not stable, yet. Don't use it in production! Thankful respects to [asaskevich/govalidator](https://github.com/asaskevich/govalidator) and [go-ozzo/ozzo-validation](https://github.com/go-ozzo/ozzo-validation) for inspiration. Feel free to contribute.\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantipitch%2Forwell","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fantipitch%2Forwell","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantipitch%2Forwell/lists"}