{"id":32355736,"url":"https://github.com/deltegui/valtruc","last_synced_at":"2026-07-09T18:31:41.082Z","repository":{"id":249573262,"uuid":"831883201","full_name":"deltegui/valtruc","owner":"deltegui","description":"Valtruc: structure validation with zero dependencies","archived":false,"fork":false,"pushed_at":"2025-09-28T10:13:16.000Z","size":77,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-24T11:37:15.098Z","etag":null,"topics":["go","validation"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/deltegui.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-07-21T22:24:37.000Z","updated_at":"2025-09-28T10:13:19.000Z","dependencies_parsed_at":"2024-11-02T16:23:56.973Z","dependency_job_id":"69e0d1fd-bd25-4859-a471-722cc065b5cc","html_url":"https://github.com/deltegui/valtruc","commit_stats":null,"previous_names":["deltegui/valtruc"],"tags_count":18,"template":false,"template_full_name":null,"purl":"pkg:github/deltegui/valtruc","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deltegui%2Fvaltruc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deltegui%2Fvaltruc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deltegui%2Fvaltruc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deltegui%2Fvaltruc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/deltegui","download_url":"https://codeload.github.com/deltegui/valtruc/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deltegui%2Fvaltruc/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35309827,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-09T02:00:07.329Z","response_time":57,"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":["go","validation"],"created_at":"2025-10-24T11:23:55.178Z","updated_at":"2026-07-09T18:31:41.076Z","avatar_url":"https://github.com/deltegui.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Valtruc: structure validator for Go\n\nValtruc is a simple, zero-dependency structure validator library for Go\n\n## Installation\n```\ngo install github.com/deltegui/valtruc@latest\n```\n\n## Basic usage\nFirst add valtruc tags to your structs\n\n```\ntype User struct {\n    Name string `valtruc:\"min=3, max=255, required\"`\n    Password string `valtruc:\"min=3, max=255, required\"`\n    AcceptConditions bool `valtruc:\"mustBeTrue\"`\n    Email string `valtruc:\"min=3, max=255, required\"`\n}\n```\n\nthen create and validate your struct\n\n```\nuser := User{\n    Name:             \"a\",\n    Password:         \"b\",\n    Email:            \"c\",\n    AcceptConditions: false,\n}\n\nerrs := vt.Validate(user)\n```\n\nThe returned `errs` is a `error` array. You can iterate over it and print the error:\n\n```\nfor _, err := range errs {\n    fmt.Println(err)\n}\n```\n\nThis code will output:\n\n```\nValidation error on struct 'User', field 'Name' (string) with value 'abcdefghijklmnopqrst': [maxStringLengthIdentifier] the field required maximum length of 10\nValidation error on struct 'User', field 'Password' (string) with value 'b': [minStringLengthIdentifier] the field required minimum length of 3\nValidation error on struct 'User', field 'AcceptConditions' (bool) with value 'false': [mustBeTrueBoolIdentifier] bool must be true\nValidation error on struct 'User', field 'Email' (string) with value 'c': [minStringLengthIdentifier] the field required minimum length of 3\n```\n\n## Error API\nYou can transform the returned `error` to `valtruc.ValidationError` type to access all validation error information. The available methods in `ValidationError` are:\n\n* `GetStructName() string`: Gets the struct name (eg. `User`)\n* `GetFieldName() string`: Get the validated field name (eg. `Email`)\n* `GetFieldTypeName() string`: Get the validated field name (eg. `string`)\n* `GetIdentifier() valtruc.ValidatorIdentifier`: Gets an validator identifier (type alias for string). You can use this to programmatically check the error type:\n```\nif (err.GetIdentifier() == valtruc.MinFloat64Identifier) {\n    // handle error knowing is MinFloat64\n}\n```\n* `GetFieldValue() string`: Get field value as string (eg. `10`)\n* `GetParam() string`: Get validator param (if you have used min validator `min=2` the returned string is `2`)\n* `Error() string`\n* `Format(str string) string`: Formats the error. You can use `${}` placeholder to show the param value. (eg. `Format(\"Must be minimum of ${}\")` will output `Must be minimum of 2`)\n\n## Create your own validators\n```\nvt := valtruc.New()\n\nconst identifier valtruc.ValidatorIdentifier = \"reverseStringIdentifier\"\n\nreverse := func(param string) valtruc.Validator {\n    return func(ctx valtruc.ValidationContext) (bool, error) {\n        str := ctx.FieldValue.String()\n        i := 0              // str\n        j := len(param) - 1 // param\n        for i \u003c len(str) \u0026\u0026 j \u003e= 0 {\n            if param[j] != str[i] {\n                return false, valtruc.NewValidationErrorMeta(\n                    ctx,\n                    \"item is not reverse\",\n                    identifier,\n                    param)\n            }\n            j--\n            i++\n        }\n        return true, nil\n    }\n}\n\nvt.AddValidator(reflect.String, \"reverse\", reverse)\n```\n\nusage:\n\n```\ntype tag struct {\n    Name string `valtruc:\"reverse=iawak, min=2\"`\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeltegui%2Fvaltruc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdeltegui%2Fvaltruc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeltegui%2Fvaltruc/lists"}