{"id":22332725,"url":"https://github.com/xgfone/go-validation","last_synced_at":"2025-03-26T07:22:14.994Z","repository":{"id":176682968,"uuid":"622129910","full_name":"xgfone/go-validation","owner":"xgfone","description":"Provide a validation framework based on the built rule.","archived":false,"fork":false,"pushed_at":"2023-12-18T06:11:33.000Z","size":56,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-11T09:37:11.978Z","etag":null,"topics":["go","golang","rule","ruler","validate","validation","validation-library","validation-rule","validation-rules","validator"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xgfone.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}},"created_at":"2023-04-01T07:54:32.000Z","updated_at":"2023-04-18T09:29:16.000Z","dependencies_parsed_at":"2023-12-18T07:25:52.675Z","dependency_job_id":"d99ecb14-0ca0-408d-8384-eb19ca4f886b","html_url":"https://github.com/xgfone/go-validation","commit_stats":null,"previous_names":["xgfone/go-validation"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xgfone%2Fgo-validation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xgfone%2Fgo-validation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xgfone%2Fgo-validation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xgfone%2Fgo-validation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xgfone","download_url":"https://codeload.github.com/xgfone/go-validation/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245606095,"owners_count":20643105,"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":["go","golang","rule","ruler","validate","validation","validation-library","validation-rule","validation-rules","validator"],"created_at":"2024-12-04T04:19:29.337Z","updated_at":"2025-03-26T07:22:14.975Z","avatar_url":"https://github.com/xgfone.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Go Validation [![Build Status](https://github.com/xgfone/go-validation/actions/workflows/go.yml/badge.svg)](https://github.com/xgfone/go-validation/actions/workflows/go.yml) [![GoDoc](https://pkg.go.dev/badge/github.com/xgfone/go-validation)](https://pkg.go.dev/github.com/xgfone/go-validation) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg?style=flat-square)](https://raw.githubusercontent.com/xgfone/go-validation/master/LICENSE)\n\nProvide a validation framework based on the built rule, supporting `Go1.16+`.\n\n\n## Install\n```shell\n$ go get -u github.com/xgfone/go-validation\n```\n\n\n## Example\nFor registering the validator and validating whether a value is valid, See [Builder](https://pkg.go.dev/github.com/xgfone/go-validation/#example-Builder).\n\n```go\npackage main\n\nimport \"github.com/xgfone/go-validation\"\n\nfunc main() {\n\t// Validate whether an integer is in [min, max].\n\tvalidation.Validate(123, `min(1) \u0026\u0026 max(200)`) // =\u003e \u003cnil\u003e\n\tvalidation.Validate(456, `min(1) \u0026\u0026 max(200)`) // =\u003e an error\n\tvalidation.Validate(123, `ranger(1, 200)`)     // =\u003e \u003cnil\u003e\n\tvalidation.Validate(456, `ranger(1, 200)`)     // =\u003e an error\n\n\t// Validate whether an string is one of a string list.\n\tvalidation.Validate(\"a\", `oneof(\"a\", \"b\", \"c\")`) // =\u003e \u003cnil\u003e\n\tvalidation.Validate(\"d\", `oneof(\"a\", \"b\", \"c\")`) // =\u003e an error\n\n\t// Validate whether an string is an integer string that can be parsed to an integer.\n\tvalidation.Validate(\"123\", `isinteger`)  // =\u003e \u003cnil\u003e\n\tvalidation.Validate(\"+123\", `isinteger`) // =\u003e \u003cnil\u003e\n\tvalidation.Validate(\"-123\", `isinteger`) // =\u003e \u003cnil\u003e\n\tvalidation.Validate(\"12.3\", `isinteger`) // =\u003e an error\n\tvalidation.Validate(\"abc\", `isinteger`)  // =\u003e an error\n\n\t// Validate whether an string is an float string that can be parsed to an float.\n\tvalidation.Validate(\"123\", `isnumber`)  // =\u003e \u003cnil\u003e\n\tvalidation.Validate(\"12.3\", `isnumber`) // =\u003e \u003cnil\u003e\n\tvalidation.Validate(\"-1.2\", `isnumber`) // =\u003e \u003cnil\u003e\n\tvalidation.Validate(\"123.\", `isnumber`) // =\u003e \u003cnil\u003e\n\tvalidation.Validate(\".123\", `isnumber`) // =\u003e \u003cnil\u003e\n\tvalidation.Validate(\"abc\", `isnumber`)  // =\u003e an error\n\n\t// Validate whether a value is ZERO.\n\tvalidation.Validate(0, `zero`)     // =\u003e \u003cnil\u003e\n\tvalidation.Validate(1, `zero`)     // =\u003e an error\n\tvalidation.Validate(\"\", `zero`)    // =\u003e \u003cnil\u003e\n\tvalidation.Validate(\"0\", `zero`)   // =\u003e an error\n\tvalidation.Validate(false, `zero`) // =\u003e \u003cnil\u003e\n\tvalidation.Validate(true, `zero`)  // =\u003e an error\n\tvar p *int\n\tvalidation.Validate(p, `zero`) // =\u003e \u003cnil\u003e\n\tp = new(int)\n\tvalidation.Validate(p, `zero`) // =\u003e an error\n\n\t// Validate whether a value is not ZERO.\n\tvalidation.Validate(0, `required`)     // =\u003e an error\n\tvalidation.Validate(1, `required`)     // =\u003e \u003cnil\u003e\n\tvalidation.Validate(\"\", `required`)    // =\u003e an error\n\tvalidation.Validate(\"0\", `required`)   // =\u003e \u003cnil\u003e\n\tvalidation.Validate(false, `required`) // =\u003e an error\n\tvalidation.Validate(true, `required`)  // =\u003e \u003cnil\u003e\n\tp = nil\n\tvalidation.Validate(p, `required`) // =\u003e an error\n\tp = new(int)\n\tvalidation.Validate(p, `required`) // =\u003e \u003cnil\u003e\n\n\t// Validate whether a slice/array is valid.\n\tvalidation.Validate([]int{1, 2}, `array(min(1), max(10))`)  // slice, =\u003e \u003cnil\u003e\n\tvalidation.Validate([3]int{1, 2}, `array(min(1), max(10))`) // array, =\u003e an error\n\n\t// Validate whether a map(key, value or key-value) is valid.\n\tmaps := map[int]string{0: \"a\", 1: \"b\"}\n\tvalidation.Validate(maps, `mapk(min(0), max(10))`) // =\u003e \u003cnil\u003e\n\tvalidation.Validate(maps, `mapk(min(1), max(10))`) // =\u003e an error\n\tvalidation.Validate(maps, `mapv(oneof(\"a\", \"b\"))`) // =\u003e \u003cnil\u003e\n\tvalidation.Validate(maps, `mapv(oneof(\"a\", \"c\"))`) // =\u003e an error\n\n// For the validation rule, it support the multi-level AND/OR. For example,\n// - \"min(100) \u0026\u0026 max(200)\"\n//    =\u003e A value, such as integer or length of string/slice, in [100, 200] is valid.\n// - \"min(200) || max(100)\"\n//    =\u003e A value, such as integer or length of string/slice, in (-∞, 100] or [200, +∞) is valid.\n// - \"(min(200) || max(100)) \u0026\u0026 required)\"\n//    =\u003e Same as \"min(200) || max(100)\", but also cannot be ZERO.\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxgfone%2Fgo-validation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxgfone%2Fgo-validation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxgfone%2Fgo-validation/lists"}