{"id":47929300,"url":"https://github.com/tomasbasham/formenc","last_synced_at":"2026-04-04T07:12:08.024Z","repository":{"id":335941475,"uuid":"1146305802","full_name":"tomasbasham/formenc","owner":"tomasbasham","description":"A module providing encoding and decoding of form data","archived":false,"fork":false,"pushed_at":"2026-02-23T23:06:58.000Z","size":26,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-02-24T05:43:35.712Z","etag":null,"topics":["golang"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":false,"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/tomasbasham.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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":"2026-01-30T22:29:05.000Z","updated_at":"2026-02-23T23:07:02.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/tomasbasham/formenc","commit_stats":null,"previous_names":["tomasbasham/formenc"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tomasbasham/formenc","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomasbasham%2Fformenc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomasbasham%2Fformenc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomasbasham%2Fformenc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomasbasham%2Fformenc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tomasbasham","download_url":"https://codeload.github.com/tomasbasham/formenc/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomasbasham%2Fformenc/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31390945,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-04T04:26:24.776Z","status":"ssl_error","status_checked_at":"2026-04-04T04:23:34.147Z","response_time":60,"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":["golang"],"created_at":"2026-04-04T07:12:07.243Z","updated_at":"2026-04-04T07:12:08.004Z","avatar_url":"https://github.com/tomasbasham.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# formenc [![test](https://github.com/tomasbasham/formenc/actions/workflows/test.yaml/badge.svg?event=push)](https://github.com/tomasbasham/formenc/actions/workflows/test.yaml)\n\nA Go module providing encoding and decoding of form data (e.g.,\n`application/x-www-form-urlencoded` and `multipart/form-data`) into Go types,\nwith support for nested structures, slices, and maps. Built on reflection,\n`formenc` provides type-safe encoding and decoding whilst preserving the\nstructure of complex data types.\n\n## Prerequisites\n\nYou will need the following things properly installed on your computer:\n\n- [Go](https://golang.org/): any one of the **three latest major**\n  [releases](https://golang.org/doc/devel/release.html)\n\n## Installation\n\nWith [Go module](https://go.dev/wiki/Modules) support (Go 1.11+), simply add the\nfollowing import\n\n```go\nimport \"github.com/tomasbasham/formenc\"\n```\n\nto your code, and then `go [build|run|test]` will automatically fetch the\nnecessary dependencies.\n\nOtherwise, to install the `formenc` module, run the following command:\n\n```bash\ngo get -u github.com/tomasbasham/formenc\n```\n\n## Usage\n\nTo use this module, import it into your Go code and call `Marshal` to encode\nstructs or maps into form data, or `Unmarshal` to decode form data back into Go\nvalues.\n\n### Encoding\n\nTo encode a Go struct or map into form data, use the `formenc.Marshal` function.\n\n```go\ntype Person struct {\n    Name  string   `form:\"name\"`\n    Age   int      `form:\"age\"`\n    Tags  []string `form:\"tags\"`\n}\n\np := Person{\n    Name: \"Alice\",\n    Age:  30,\n    Tags: []string{\"admin\", \"user\"},\n}\n\ndata, err := formenc.Marshal(p)\n// data: \"age=30\u0026name=Alice\u0026tags[]=admin\u0026tags[]=user\"\n```\n\nYou can also encode maps:\n\n```go\nm := map[string]any{\n    \"user\": map[string]any{\n        \"name\": \"Bob\",\n        \"age\":  25,\n    },\n}\n\ndata, err := formenc.Marshal(m)\n// data: \"user[age]=25\u0026user[name]=Bob\"\n```\n\n### Decoding\n\nTo decode form data into a Go struct or map, use the `formenc.Unmarshal`\nfunction.\n\n```go\ndata := \"name=Charlie\u0026age=35\u0026tags[]=developer\u0026tags[]=reviewer\"\n\nvar p Person\nerr := formenc.Unmarshal([]byte(data), \u0026p)\n// p.Name: \"Charlie\"\n// p.Age: 35\n// p.Tags: []string{\"developer\", \"reviewer\"}\n```\n\nFor dynamic structures, decode into map[string]any:\n\n```go\ndata := \"user[name]=Diana\u0026user[permissions][]=read\u0026user[permissions][]=write\"\n\nvar m map[string]any\nerr := formenc.Unmarshal([]byte(data), \u0026m)\n// m: map[string]any{\n//     \"user\": map[string]any{\n//         \"name\": \"Diana\",\n//         \"permissions\": []any{\"read\", \"write\"},\n//     },\n// }\n```\n\n### Streaming\n\nUse `Encoder` and `Decoder` for working with `io.Reader` and `io.Writer`:\n\n```go\n// Encoding\nvar buf bytes.Buffer\nenc := formenc.NewEncoder(\u0026buf)\nerr := enc.Encode(person)\n\n// Decoding\ndec := formenc.NewDecoder(request.Body)\nvar person Person\nerr := dec.Decode(\u0026person)\n```\n\n### Struct Tags\n\nControl field behaviour using struct tags:\n\n```go\ntype Config struct {\n    APIKey    string `form:\"api_key\"`          // Custom field name\n    Debug     bool   `form:\"debug,omitempty\"`  // Omit if zero value\n    Internal  string `form:\"-\"`                // Always ignore\n}\n```\n\n### Custom Marshalling\n\nImplement `Marshaler` or `Unmarshaler` for custom encoding logic:\n\n```go\ntype Timestamp time.Time\n\nfunc (t Timestamp) MarshalForm() (string, error) {\n    return time.Time(t).Format(time.RFC3339), nil\n}\n\nfunc (t *Timestamp) UnmarshalForm(s string) error {\n    parsed, err := time.Parse(time.RFC3339, s)\n    if err != nil {\n        return err\n    }\n    *t = Timestamp(parsed)\n    return nil\n}\n```\n\n### Type Guarantees\n\n| Target type       | Guarantee           |\n| ----------------- | ------------------- |\n| Structs           | Typed, validated    |\n| Typed maps/slices | Typed, validated    |\n| `map[string]any`  | Perfect round-trip  |\n| `[]any`           | Perfect round-trip  |\n| Mixed nesting     | Structure preserved |\n\n## License\n\nThis project is licensed under the [MIT License](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomasbasham%2Fformenc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftomasbasham%2Fformenc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomasbasham%2Fformenc/lists"}