{"id":37184819,"url":"https://github.com/victorcph/validator","last_synced_at":"2026-01-14T21:22:21.962Z","repository":{"id":57485653,"uuid":"181899540","full_name":"VictorCPH/validator","owner":"VictorCPH","description":"Validator is a http request parameters checker","archived":false,"fork":false,"pushed_at":"2020-07-27T15:08:41.000Z","size":338,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-06-21T13:14:49.133Z","etag":null,"topics":["golang","http","parameters","reflect","validation"],"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/VictorCPH.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":"2019-04-17T13:39:39.000Z","updated_at":"2020-07-27T15:48:12.000Z","dependencies_parsed_at":"2022-08-30T16:00:32.753Z","dependency_job_id":null,"html_url":"https://github.com/VictorCPH/validator","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/VictorCPH/validator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VictorCPH%2Fvalidator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VictorCPH%2Fvalidator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VictorCPH%2Fvalidator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VictorCPH%2Fvalidator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/VictorCPH","download_url":"https://codeload.github.com/VictorCPH/validator/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VictorCPH%2Fvalidator/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28434855,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T18:57:19.464Z","status":"ssl_error","status_checked_at":"2026-01-14T18:52:48.501Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["golang","http","parameters","reflect","validation"],"created_at":"2026-01-14T21:22:21.230Z","updated_at":"2026-01-14T21:22:21.926Z","avatar_url":"https://github.com/VictorCPH.png","language":"Go","readme":"# Validator\n\n[![Build Status](https://travis-ci.org/VictorCPH/validator.svg?branch=master)](https://travis-ci.org/VictorCPH/validator)\n\nValidator is a http request parameters checker.\n\n## Installation\n\nMake sure that Go is installed on your computer. Type the following command in your terminal:\n\n```sh\n$ go get github.com/VictorCPH/validator\n```\n\n## Import package in your project\n\nAdd following line in your `*.go` file:\n\n```golang\nimport \"github.com/VictorCPH/validator\"\n```\n\n## Usage\n\n### Basic\n\n```golang\n// examples/basic/main.go\npackage main\n\nimport (\n\t\"encoding/json\"\n\t\"fmt\"\n\t\"net/http\"\n\n\t\"github.com/VictorCPH/validator\"\n)\n\ntype param struct {\n\tName      string    `form:\"name\" json:\"name\" valid:\"required\" regexp:\"^[a-zA-Z_][a-zA-Z_]*$\"`\n\tAge       int       `form:\"age\" json:\"age\" valid:\"required\" range:\"18|25\"`\n\tPassed    bool      `form:\"passed\" json:\"passed\" valid:\"required\"`\n\tScore     float32   `form:\"score\" json:\"score\" valid:\"required\" min:\"60.0\"`\n\tArea      float64   `form:\"area\" json:\"area\" valid:\"required\" max:\"200.0\"`\n\tSide      string    `form:\"side\" json:\"side\" valid:\"required\" values:\"front|back\"`\n\tFriends   []string  `form:\"friends\" json:\"friends\" valid:\"required\" regexp:\"^[a-zA-Z_][a-zA-Z_]*$\"`\n\tScores    []float32 `form:\"scores\" json:\"scores\" valid:\"required\" range:\"60|100\"`\n\tExtraInfo string    `form:\"extra_info\" json:\"extra_info\" valid:\"optional\" default:\"hello\"`\n}\n\nfunc handler(w http.ResponseWriter, r *http.Request) {\n\tobj := param{}\n\terr := validator.Bind(r, \u0026obj)\n\tif err != nil {\n\t\tjson.NewEncoder(w).Encode(map[string]string{\"msg\": err.Error()})\n\t} else {\n\t\tjson.NewEncoder(w).Encode(obj)\n\t}\n}\n\nfunc main() {\n\thttp.HandleFunc(\"/\", handler)\n\tfmt.Println(\"Listening on port: 8080\")\n\thttp.ListenAndServe(\":8080\", nil)\n}\n```\n\n```sh\n# run examples/basic/main.go and visit localhost:8080\n$ go run examples/basic/main.go\n```\n\nTest it with form:\n\n```\n$ curl -v -XPOST \"localhost:8080\" \\\n  -H \"Content-Type: application/x-www-form-urlencoded\" \\\n  -d \"name=ming\" \\\n  -d \"age=20\" \\\n  -d \"passed=true\" \\\n  -d \"score=86.5\" \\\n  -d \"area=148.898877383\" \\\n  -d \"side=front\" \\\n  -d \"friends[]=Mary\" -d \"friends[]=Jack\" \\\n  -d \"scores[]=68.5\" -d \"scores[]=73.5\"\n```\n\nTest it with query string:\n\n```\n$ curl -v -g -XGET \"localhost:8080/?name=ming\u0026age=20\u0026passed=true\u0026score=86.5\u0026area=148.898877383\u0026side=front\u0026friends[]=Mary\u0026friends[]=Jack\u0026scores[]=68.5\u0026scores[]=73.5\"\n```\n\nTest it with json:\n\n```\n$ curl -v -XPOST \"localhost:8080\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"name\":\"ming\",\"age\":20,\"passed\":true,\"score\":86.5,\"area\":148.898877383,\"side\":\"front\",\"friends\":[\"Mary\",\"Jack\"],\"scores\":[68.5,73.5],\"extra_info\":\"hello\"}'\n```\n\n### Multipart file\n\n```golang\n// examples/file_bind/main.go\npackage main\n\nimport (\n\t\"encoding/json\"\n\t\"fmt\"\n\t\"net/http\"\n\n\t\"github.com/VictorCPH/validator\"\n)\n\ntype fileParam struct {\n\tImage []byte `form:\"image\" valid:\"required\" type:\"file\" max_size:\"61440\"`\n\tName  string `form:\"name\" valid:\"required\" regexp:\"^[a-zA-Z_][a-zA-Z_]*$\"`\n}\n\nfunc handler(w http.ResponseWriter, r *http.Request) {\n\tobj := fileParam{}\n\terr := validator.Bind(r, \u0026obj)\n\tif err != nil {\n\t\tjson.NewEncoder(w).Encode(map[string]string{\"msg\": err.Error()})\n\t} else {\n\t\tjson.NewEncoder(w).Encode(map[string]int{\"image_size\": len(obj.Image)})\n\t}\n}\n\nfunc main() {\n\thttp.HandleFunc(\"/\", handler)\n\tfmt.Println(\"Listening on port: 8080\")\n\thttp.ListenAndServe(\":8080\", nil)\n}\n```\n\n```sh\n# run examples/file_bind/main.go and visit localhost:8080\n$ go run examples/file_bind/main.go\n```\n\nTest it with:\n\n```sh\n$ curl -v -XPOST \"localhost:8080\" \\\n  -F \"image=@testdata/Go-Logo_Aqua.jpg\" \\\n  -F \"name=ming\"\n```\n\n### Base64 string\n\n```golang\n// examples/base64_bind/main.go\npackage main\n\nimport (\n\t\"encoding/json\"\n\t\"fmt\"\n\t\"net/http\"\n\n\t\"github.com/VictorCPH/validator\"\n)\n\ntype base64Param struct {\n\tLabel []byte `form:\"label\" valid:\"required\" type:\"base64\"`\n}\n\nfunc handler(w http.ResponseWriter, r *http.Request) {\n\tobj := base64Param{}\n\terr := validator.Bind(r, \u0026obj)\n\tif err != nil {\n\t\tjson.NewEncoder(w).Encode(map[string]string{\"msg\": err.Error()})\n\t} else {\n\t\tjson.NewEncoder(w).Encode(map[string]string{\"label\": string(obj.Label)})\n\t}\n}\n\nfunc main() {\n\thttp.HandleFunc(\"/\", handler)\n\tfmt.Println(\"Listening on port: 8080\")\n\thttp.ListenAndServe(\":8080\", nil)\n}\n```\n\n```sh\n# run examples/base64_bind/main.go and visit localhost:8080\n$ go run examples/base64_bind/main.go\n```\n\nTest it with:\n\n```sh\n$ curl -v -XPOST \"localhost:8080\" \\\n  -d \"label=aGVsbG8=\"\n```\n\n## Support tags\n\n``` sh\nform, json, valid, default, type, values, min, max, range, regexp, max_size\n```\n\n- if use form format, you shold contain a `form` tag to give the name of the field.\n- if use json format, you shold contain a `json` tag to give the name of the field.\n- every param validation should contain a `valid` tag, it must be `required` or `optional`.\n- `default` tag can only be used with `optional`.\n- `values` tag can only be used with `int float32 float64 bool string`.\n- `min, max, range` tag can only be used with `int, float32, float64`.\n- `regexp` tag can only be used with `string`.\n- `type` tag now only support `file` and `base64`.\n- if `type:\"file\"`, it will read file as `[]byte`.\n- if `type:\"base64\"`, it will read base64 string, then decode it and save as `[]byte`.\n- `max_size` tag can only be used with `type:\"file\"`, it will check the max size of file.\n\n\nSupported Types:\n\n```sh\nint, bool, float32, float64, string, slice, []byte\n```\n\nIf you has more demands, report an [issue](https://github.com/VictorCPH/validator/issues/new), or open up a [pull request](https://github.com/VictorCPH/validator/pulls).\n\n## License\n\nThe repo is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvictorcph%2Fvalidator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvictorcph%2Fvalidator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvictorcph%2Fvalidator/lists"}