{"id":46718132,"url":"https://github.com/ezartsh/inrequest","last_synced_at":"2026-03-09T11:04:12.998Z","repository":{"id":190555136,"uuid":"682885033","full_name":"ezartsh/inrequest","owner":"ezartsh","description":"Go package for parsing HTTP request bodies (form-data, JSON, query params) into maps and structs with automatic type conversion and file upload support.","archived":false,"fork":false,"pushed_at":"2025-12-05T09:14:08.000Z","size":46,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-08T18:08:35.212Z","etag":null,"topics":["file-upload","form-data","go","golang","http","json","multipart","parser","request-parser","struct-binding"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/ezartsh/inrequest","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/ezartsh.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-08-25T05:19:44.000Z","updated_at":"2025-12-05T09:22:38.000Z","dependencies_parsed_at":"2023-11-08T11:38:01.694Z","dependency_job_id":"ede79ec2-8468-4068-9d34-85e11a82c7d6","html_url":"https://github.com/ezartsh/inrequest","commit_stats":null,"previous_names":["ezartsh/inrequest"],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/ezartsh/inrequest","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ezartsh%2Finrequest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ezartsh%2Finrequest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ezartsh%2Finrequest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ezartsh%2Finrequest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ezartsh","download_url":"https://codeload.github.com/ezartsh/inrequest/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ezartsh%2Finrequest/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30291851,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-09T02:57:19.223Z","status":"ssl_error","status_checked_at":"2026-03-09T02:56:26.373Z","response_time":61,"last_error":"SSL_read: 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":["file-upload","form-data","go","golang","http","json","multipart","parser","request-parser","struct-binding"],"created_at":"2026-03-09T11:04:12.079Z","updated_at":"2026-03-09T11:04:12.980Z","avatar_url":"https://github.com/ezartsh.png","language":"Go","readme":"# Go Inrequest\n\n[![Go Version](https://img.shields.io/badge/Go-1.17+-00ADD8?style=flat\u0026logo=go)](https://go.dev/)\n[![License](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)\n[![Go Report Card](https://goreportcard.com/badge/github.com/ezartsh/inrequest)](https://goreportcard.com/report/github.com/ezartsh/inrequest)\n\n**Golang package for transforming HTTP request body into Go maps and structs.**\n\nSupports multiple content types:\n- `multipart/form-data` (with file uploads)\n- `application/x-www-form-urlencoded`\n- `application/json`\n- Query string parameters\n\n---\n\n## Installation\n\nRequires [Go](https://go.dev/) 1.17+\n\n```sh\ngo get github.com/ezartsh/inrequest\n```\n\n## Import\n\n```go\nimport \"github.com/ezartsh/inrequest\"\n```\n\n---\n\n## Quick Start\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"net/http\"\n    \"github.com/ezartsh/inrequest\"\n)\n\nfunc main() {\n    http.HandleFunc(\"/submit\", func(w http.ResponseWriter, r *http.Request) {\n        // Parse form data\n        req := inrequest.FormData(r)\n        defer req.Cleanup() // Optional: clean up temp files\n        \n        fmt.Println(req.ToMap())\n        // output: map[first_name:John last_name:Smith]\n    })\n    \n    http.ListenAndServe(\":8080\", nil)\n}\n```\n\n---\n\n## API Reference\n\n### Entry Functions\n\n| Function | Description |\n|----------|-------------|\n| `FormData(r *http.Request)` | Parse multipart/form-data or url-encoded form |\n| `FormDataWithOptions(r *http.Request, opts Options)` | Parse form with custom options |\n| `Query(r *http.Request)` | Parse query string parameters |\n| `Json(r *http.Request)` | Parse JSON request body |\n| `Parse(r *http.Request)` | Auto-detect and parse based on Content-Type |\n\n### Options\n\n```go\ntype Options struct {\n    MaxMemory int64 // Max memory for multipart parsing (default: 32MB)\n}\n```\n\n### Request Interface\n\nAll request types implement the `Request` interface:\n\n```go\ntype Request interface {\n    ToMap() RequestValue                    // Get as map[string]interface{}\n    ToBind(model interface{}) error         // Bind to struct\n    ToJsonByte() ([]byte, error)            // Get as JSON bytes\n    ToJsonString() (string, error)          // Get as JSON string\n}\n```\n\n### FormRequest Additional Methods\n\n```go\n// Cleanup removes temporary files created during multipart form parsing.\n// Optional but recommended for high-traffic servers.\nfunc (r FormRequest) Cleanup()\n```\n\n### Types\n\n```go\n// RequestValue is the parsed request data\ntype RequestValue = map[string]interface{}\n\n// FileHeaders represents multiple uploaded files for a single field\ntype FileHeaders []*multipart.FileHeader\n```\n\n---\n\n## Request Body Types\n\n- [Form Data](#1-form-data)\n- [Query String](#2-query-string)\n- [JSON Request](#3-json-request)\n- [Auto Parse](#4-auto-parse)\n\n---\n\n## 1. Form Data\n\n### Basic Example\n\n```html\n\u003cform action=\"/submit\" method=\"POST\"\u003e\n    \u003cinput type=\"text\" value=\"John\" name=\"first_name\"/\u003e\n    \u003cinput type=\"text\" value=\"Smith\" name=\"last_name\"/\u003e\n\u003c/form\u003e\n```\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"net/http\"\n    \"github.com/ezartsh/inrequest\"\n)\n\ntype BodyRequest struct {\n    FirstName string `json:\"first_name\"`\n    LastName  string `json:\"last_name\"`\n}\n\nfunc main() {\n    http.HandleFunc(\"/submit\", func(w http.ResponseWriter, r *http.Request) {\n        req := inrequest.FormData(r)\n        defer req.Cleanup()\n        \n        // Get as map\n        fmt.Println(req.ToMap())\n        // output: map[first_name:John last_name:Smith]\n        \n        // Bind to struct\n        var body BodyRequest\n        req.ToBind(\u0026body)\n        fmt.Printf(\"My name is %s %s\\n\", body.FirstName, body.LastName)\n        // output: My name is John Smith\n        \n        // Get as JSON string\n        if jsonStr, err := req.ToJsonString(); err == nil {\n            fmt.Println(jsonStr)\n            // output: {\"first_name\":\"John\",\"last_name\":\"Smith\"}\n        }\n    })\n    \n    http.ListenAndServe(\":8080\", nil)\n}\n```\n\n### Nested Arrays and Objects\n\n```html\n\u003cform action=\"/submit\" method=\"POST\" enctype=\"multipart/form-data\"\u003e\n    \u003cinput type=\"text\" value=\"John\" name=\"names[0]\"/\u003e\n    \u003cinput type=\"text\" value=\"Smith\" name=\"names[1]\"/\u003e\n    \u003cinput type=\"text\" value=\"Doe\" name=\"names[2]\"/\u003e\n    \n    \u003cinput type=\"text\" value=\"Title 1\" name=\"attachments[0][title]\"/\u003e\n    \u003ctextarea name=\"attachments[0][description]\"\u003eDescription 1\u003c/textarea\u003e\n    \u003cinput type=\"file\" name=\"attachments[0][file]\"/\u003e\n    \n    \u003cinput type=\"text\" value=\"Title 2\" name=\"attachments[1][title]\"/\u003e\n    \u003ctextarea name=\"attachments[1][description]\"\u003eDescription 2\u003c/textarea\u003e\n    \u003cinput type=\"file\" name=\"attachments[1][file]\"/\u003e\n\u003c/form\u003e\n```\n\n```go\nreq := inrequest.FormData(r)\ndefer req.Cleanup()\n\njsonStr, _ := req.ToJsonString()\nfmt.Println(jsonStr)\n```\n\n**Output:**\n```json\n{\n    \"names\": [\"John\", \"Smith\", \"Doe\"],\n    \"attachments\": [\n        {\n            \"title\": \"Title 1\",\n            \"description\": \"Description 1\",\n            \"file\": {\n                \"Filename\": \"document.pdf\",\n                \"Header\": {\n                    \"Content-Type\": [\"application/pdf\"]\n                },\n                \"Size\": 13264\n            }\n        },\n        {\n            \"title\": \"Title 2\",\n            \"description\": \"Description 2\",\n            \"file\": {\n                \"Filename\": \"image.png\",\n                \"Header\": {\n                    \"Content-Type\": [\"image/png\"]\n                },\n                \"Size\": 8192\n            }\n        }\n    ]\n}\n```\n\n### Multiple File Uploads\n\nFor multiple files with the same field name, use `FileHeaders`:\n\n```html\n\u003cinput type=\"file\" name=\"documents[]\" multiple/\u003e\n```\n\n```go\ntype UploadRequest struct {\n    Documents inrequest.FileHeaders `json:\"documents\"`\n}\n\nreq := inrequest.FormData(r)\ndefer req.Cleanup()\n\nvar upload UploadRequest\nreq.ToBind(\u0026upload)\n\nfor _, file := range upload.Documents {\n    fmt.Printf(\"File: %s, Size: %d\\n\", file.Filename, file.Size)\n}\n```\n\n### Custom Memory Limit\n\n```go\nreq := inrequest.FormDataWithOptions(r, inrequest.Options{\n    MaxMemory: 10 \u003c\u003c 20, // 10 MB\n})\ndefer req.Cleanup()\n```\n\n---\n\n## 2. Query String\n\n```\nGET /search?utm_source=google\u0026callback_url=http://localhost:3000\u0026status=active\n```\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"net/http\"\n    \"github.com/ezartsh/inrequest\"\n)\n\nfunc main() {\n    http.HandleFunc(\"/search\", func(w http.ResponseWriter, r *http.Request) {\n        req := inrequest.Query(r)\n        \n        fmt.Println(req.ToMap())\n        // output: map[callback_url:http://localhost:3000 status:active utm_source:google]\n        \n        if jsonStr, err := req.ToJsonString(); err == nil {\n            fmt.Println(jsonStr)\n            // output: {\"callback_url\":\"http://localhost:3000\",\"status\":\"active\",\"utm_source\":\"google\"}\n        }\n    })\n    \n    http.ListenAndServe(\":8080\", nil)\n}\n```\n\n### Nested Query Parameters\n\n```\nGET /filter?filters[status]=active\u0026filters[category]=tech\u0026items[0]=a\u0026items[1]=b\n```\n\n```go\nreq := inrequest.Query(r)\nfmt.Println(req.ToMap())\n// output: map[filters:map[status:active category:tech] items:[a b]]\n```\n\n---\n\n## 3. JSON Request\n\n```json\n{\n    \"first_name\": \"John\",\n    \"last_name\": \"Smith\",\n    \"age\": 31\n}\n```\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"net/http\"\n    \"github.com/ezartsh/inrequest\"\n)\n\ntype Person struct {\n    FirstName string `json:\"first_name\"`\n    LastName  string `json:\"last_name\"`\n    Age       int    `json:\"age\"`\n}\n\nfunc main() {\n    http.HandleFunc(\"/api/person\", func(w http.ResponseWriter, r *http.Request) {\n        req := inrequest.Json(r)\n        \n        fmt.Println(req.ToMap())\n        // output: map[age:31 first_name:John last_name:Smith]\n        \n        var person Person\n        req.ToBind(\u0026person)\n        fmt.Printf(\"%s is %d years old\\n\", person.FirstName, person.Age)\n        // output: John is 31 years old\n        \n        if jsonStr, err := req.ToJsonString(); err == nil {\n            fmt.Println(jsonStr)\n            // output: {\"age\":31,\"first_name\":\"John\",\"last_name\":\"Smith\"}\n        }\n    })\n    \n    http.ListenAndServe(\":8080\", nil)\n}\n```\n\n---\n\n## 4. Auto Parse\n\nUse `Parse()` to automatically detect and parse based on `Content-Type`:\n\n```go\nhttp.HandleFunc(\"/api/data\", func(w http.ResponseWriter, r *http.Request) {\n    req := inrequest.Parse(r)\n    \n    // Works with any content type:\n    // - application/json\n    // - multipart/form-data\n    // - application/x-www-form-urlencoded\n    // - Falls back to query string\n    \n    fmt.Println(req.ToMap())\n})\n```\n\n---\n\n## Type Conversion\n\nThe library automatically converts string values to appropriate Go types:\n\n| Input | Output Type |\n|-------|-------------|\n| `\"123\"` | `int` |\n| `\"3.14\"` | `float64` |\n| `\"true\"`, `\"false\"` | `bool` |\n| `\"null\"` | `nil` |\n| Other strings | `string` |\n\n---\n\n## Binding to Structs\n\nUse `ToBind()` to bind request data to a struct. The struct fields should have `json` tags:\n\n```go\ntype CreateUserRequest struct {\n    Name     string                  `json:\"name\"`\n    Email    string                  `json:\"email\"`\n    Age      int                     `json:\"age\"`\n    Active   bool                    `json:\"active\"`\n    Avatar   *multipart.FileHeader   `json:\"avatar\"`      // Single file\n    Photos   inrequest.FileHeaders   `json:\"photos\"`      // Multiple files\n}\n\nreq := inrequest.FormData(r)\ndefer req.Cleanup()\n\nvar user CreateUserRequest\nif err := req.ToBind(\u0026user); err != nil {\n    http.Error(w, err.Error(), http.StatusBadRequest)\n    return\n}\n\n// Access file\nif user.Avatar != nil {\n    fmt.Printf(\"Avatar: %s\\n\", user.Avatar.Filename)\n}\n\n// Access multiple files\nfor _, photo := range user.Photos {\n    fmt.Printf(\"Photo: %s\\n\", photo.Filename)\n}\n```\n\n---\n\n## Performance\n\nThe library is optimized for performance:\n\n| Operation | Time |\n|-----------|------|\n| Simple form (5 fields) | ~5 µs |\n| Complex nested form | ~50 µs |\n| Large form (100 fields) | ~200 µs |\n| File upload | ~500 µs |\n\nMemory allocation is minimal, and temporary files are cleaned up with `Cleanup()`.\n\n---\n\n## Contributing\n\nIf you have a bug report or feature request, you can [open an issue](https://github.com/ezartsh/inrequest/issues/new), and [pull requests](https://github.com/ezartsh/inrequest/pulls) are also welcome.\n\n## License\n\n`inrequest` is released under the MIT license. See [LICENSE](LICENSE) for details.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fezartsh%2Finrequest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fezartsh%2Finrequest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fezartsh%2Finrequest/lists"}