{"id":19655502,"url":"https://github.com/ritwickdey/querydecoder","last_synced_at":"2026-03-14T06:33:44.945Z","repository":{"id":57647497,"uuid":"443253954","full_name":"ritwickdey/querydecoder","owner":"ritwickdey","description":"Go Package to populate struct from optional query parameters using 'query' tag","archived":false,"fork":false,"pushed_at":"2022-01-01T11:28:12.000Z","size":22,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-06-20T16:35:18.853Z","etag":null,"topics":["decoder","golang","query"],"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/ritwickdey.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":"2021-12-31T04:40:23.000Z","updated_at":"2023-11-27T01:05:05.000Z","dependencies_parsed_at":"2022-08-25T08:10:44.109Z","dependency_job_id":null,"html_url":"https://github.com/ritwickdey/querydecoder","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ritwickdey%2Fquerydecoder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ritwickdey%2Fquerydecoder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ritwickdey%2Fquerydecoder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ritwickdey%2Fquerydecoder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ritwickdey","download_url":"https://codeload.github.com/ritwickdey/querydecoder/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224126089,"owners_count":17259979,"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":["decoder","golang","query"],"created_at":"2024-11-11T15:21:46.572Z","updated_at":"2026-03-14T06:33:44.885Z","avatar_url":"https://github.com/ritwickdey.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# querydecoder\n\n`querydecoder` is a Go Package for populating struct from optional query parameters using 'query' tag. This package can be used to populate value into primitive variable.\n\n\n#### Example\n```go\nimport (\n\t\"github.com/ritwickdey/querydecoder\"\n)\n\ntype User struct {\n\tIsSuperUser bool   `query:\"is_super_user\"`\n\tUserName    string `query:\"user_name\"`\n\tUserID      int64  `query:\"user_id\"`\n}\n\n// Parse by struct tags\nfunc ServeHTTP(w http.ResponseWriter, r *http.Request) {\n    \n    u1 := User{}\n    query := r.URL.Query()\n    // Decode into struct\n    err := querydecoder.New(query).Decode(\u0026u1)\n   \n    if err != nil {\n        panic(err)\n    }\n   \n   log.Println(u1) \n\n}\n\n// OR,\n// Parse by key\nfunc ServeHTTP2(w http.ResponseWriter, r *http.Request) {\n  \n    var isDog bool\n    err := querydecoder.New(query).DecodeField(\"is_dog\", \u0026isDog)\n    // if `is_dog` query param is not there, it'll not modity variable.\n\n    if err != nil {\n        panic(err)\n    }\n\n}\n\n```\n\n\n#### Benchmark \n\n```\ngoos: darwin\ngoarch: arm64 (Mac M1 Chip)\npkg: github.com/ritwickdey/querydecoder\n\nBenchmarkDecode-8                2019590                603.1 ns/op //Parse by struct tags\nBenchmarkDecodeField-8          10521158                113.1 ns/op //Parse by key\nBenchmarkManualDecode-8         25947067                46.74 ns/op //Manual parsing\n\nBenchmarkJsonUnmarshal-8          883681                 1413 ns/op //json.Unmarshal - Unrelated, but added to compare.\n\n\n```\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fritwickdey%2Fquerydecoder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fritwickdey%2Fquerydecoder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fritwickdey%2Fquerydecoder/lists"}