{"id":15533447,"url":"https://github.com/datek/golidator","last_synced_at":"2025-06-11T12:33:57.976Z","repository":{"id":64298915,"uuid":"566883863","full_name":"DAtek/golidator","owner":"DAtek","description":"Lightweight extensible validation library inspired by Pydantic","archived":false,"fork":false,"pushed_at":"2024-01-22T19:17:09.000Z","size":11,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-14T10:59:22.047Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/DAtek.png","metadata":{"files":{"readme":"README.md","changelog":"changelog.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-11-16T16:08:31.000Z","updated_at":"2022-11-21T11:08:48.000Z","dependencies_parsed_at":"2024-06-20T02:23:21.035Z","dependency_job_id":null,"html_url":"https://github.com/DAtek/golidator","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DAtek%2Fgolidator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DAtek%2Fgolidator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DAtek%2Fgolidator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DAtek%2Fgolidator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DAtek","download_url":"https://codeload.github.com/DAtek/golidator/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241801194,"owners_count":20022383,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2024-10-02T11:37:05.396Z","updated_at":"2025-03-04T06:42:29.088Z","avatar_url":"https://github.com/DAtek.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![codecov](https://codecov.io/gh/DAtek/golidator/graph/badge.svg?token=1QYUBN9NDN)](https://codecov.io/gh/DAtek/golidator)\n\n# Golidator\nLightweight, extensible validation library inspired by [Pydantic](https://github.com/pydantic/pydantic)\n\n## Features\n- You can use any context in the validation logic e.g. database connection\n- Fields can have multiple errors\n- Returned errors show the exact location of the erroneous fileds, you can also provide error context\n- During validation you can mutate the struct e.g. use `time.Parse()` and store the result into a different field\n\n\n## Usage\nSee [`validator_test.go`](https://github.com/DAtek/golidator/blob/main/validator_test.go)\n\n## Example\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/DAtek/golidator\"\n\t\"strings\"\n)\n\ntype CreateUserInput struct {\n\tUsername string\n\tPassword string\n}\n\nfunc (obj *CreateUserInput) GetValidators(ctx ...interface{}) golidator.ValidatorCollection {\n\tdb, ok := ctx[0].(IDatabase)\n\tif !ok {\n\t\tpanic(\"db not provided\")\n\t}\n\n\treturn golidator.ValidatorCollection{\n\t\t{Field: \"Username\", Function: func() *golidator.ValueError {\n\t\t\tif db.UserExists(obj.Username) {\n\t\t\t\treturn \u0026golidator.ValueError{ErrorType: golidator.ErrorType(\"ALREADY_EXISTS\")}\n\t\t\t}\n\t\t\treturn nil\n\t\t}},\n\t\t{Field: \"Password\", Function: func() *golidator.ValueError {\n\t\t\tminLength := 5\n\t\t\tif len(obj.Password) \u003c minLength {\n\t\t\t\treturn \u0026golidator.ValueError{\n\t\t\t\t\tErrorType: golidator.ErrorType(\"TOO_SHORT\"),\n\t\t\t\t\tContext:   map[string]any{\"min\": minLength},\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn nil\n\t\t}},\n\t\t{Field: \"Password\", Function: func() *golidator.ValueError {\n\t\t\tif !strings.ContainsAny(obj.Password, \"0123456789\") {\n\t\t\t\treturn \u0026golidator.ValueError{\n\t\t\t\t\tErrorType: golidator.ErrorType(\"MISSING_NUMBER\"),\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn nil\n\t\t}},\n\t}\n}\n\ntype IDatabase interface {\n\tUserExists(username string) bool\n}\n\ntype FakeDatabase struct{}\n\nfunc (db *FakeDatabase) UserExists(username string) bool {\n\treturn username == \"John\"\n}\n\nfunc main() {\n\tdb := \u0026FakeDatabase{}\n\tinput := \u0026CreateUserInput{\"John\", \"asd\"}\n\terr := golidator.Validate(input, db)\n\tfmt.Printf(\"%v\\n\", err)\n}\n\n```\n\u003e\u003e\u003e\n```\n3 validation error(s) for main.CreateUserInput\nUsername: ALREADY_EXISTS\nPassword: TOO_SHORT\nPassword: MISSING_NUMBER\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdatek%2Fgolidator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdatek%2Fgolidator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdatek%2Fgolidator/lists"}