{"id":19095700,"url":"https://github.com/insei/gomapper","last_synced_at":"2025-07-06T14:40:56.613Z","repository":{"id":163878465,"uuid":"639320463","full_name":"Insei/gomapper","owner":"Insei","description":"A simple structure-to-structure converter. It is an excellent choice for mapping Data Transfer Objects (DTOs) to domain models.","archived":false,"fork":false,"pushed_at":"2024-12-03T12:25:46.000Z","size":28,"stargazers_count":2,"open_issues_count":0,"forks_count":4,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-30T14:15:07.918Z","etag":null,"topics":["automapper","dto","dto-entity-mapper","dto-mapper","dto-pattern","dtos","go","golang"],"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/Insei.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,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-05-11T08:24:10.000Z","updated_at":"2024-12-03T12:24:53.000Z","dependencies_parsed_at":null,"dependency_job_id":"c36149c8-e6ab-46dd-8da0-112aa6bc6840","html_url":"https://github.com/Insei/gomapper","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/Insei/gomapper","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Insei%2Fgomapper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Insei%2Fgomapper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Insei%2Fgomapper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Insei%2Fgomapper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Insei","download_url":"https://codeload.github.com/Insei/gomapper/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Insei%2Fgomapper/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263921114,"owners_count":23530299,"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":["automapper","dto","dto-entity-mapper","dto-mapper","dto-pattern","dtos","go","golang"],"created_at":"2024-11-09T03:34:50.768Z","updated_at":"2025-07-06T14:40:56.560Z","avatar_url":"https://github.com/Insei.png","language":"Go","readme":"[![codecov](https://codecov.io/github/Insei/gomapper/graph/badge.svg?token=85LGN4NOFA)](https://codecov.io/github/Insei/gomapper)\n[![build](https://github.com/insei/gomapper/actions/workflows/go.yml/badge.svg)](https://github.com/Insei/gomapper/actions/workflows/go.yml)\n[![Goreport](https://goreportcard.com/badge/github.com/insei/gomapper)](https://goreportcard.com/report/github.com/insei/gomapper)\n[![GoDoc](https://godoc.org/github.com/insei/gomapper?status.svg)](https://godoc.org/github.com/insei/gomapper)\n# GoMapper \nGoMapper is a library for struct to struct mapping.\nThere are two use cases: Manual and Auto.\u003cbr\u003e\n* `Manual` mode allows you to specify a function to convert one structure to another.\u003cbr\u003e\n* `Auto` mode uses matching field names for automatic conversion; \nit is important that not only the field names match, but also their types. \nThis mode also supports structures in structure fields and automatically works by matching field names. \nIt's based on [fmap](https://github.com/insei/fmap) switch case and reflect based library.\n\nBoth modes are route based. In which the reflect.Type of the source structure and the type of the destination structure \nare specified. If such a route was not found, gomapper will return an error.\n\nAlso `gomapper` support slices, you don't need to specify types of slices for mapping.\n\n## Installation\n\n```bash\ngo get github.com/insei/gomapper@latest\n```\n\n## Examples\nYou can found a lot of examples in tests.\u003cbr\u003e\nManual route.\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/insei/gomapper\"\n)\n\ntype Source struct {\n\tName string\n\tAge  uint8\n}\n\ntype Dest struct {\n\tNameCustom string\n\tAge        uint8\n}\n\nfunc main() {\n\terr := gomapper.AddRoute[Source, Dest](func(source Source, dest *Dest) error {\n\t\tdest.NameCustom = source.Name\n\t\tdest.Age = source.Age\n\t\treturn nil\n\t})\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\ts := Source{\n\t\tName: \"DefaultName\",\n\t\tAge:  16,\n\t}\n\tdest, err := gomapper.MapTo[Dest](s) \n\t// or gomapper.MapTo[Dest](\u0026s)\n\t// or d := Dest{}\n\t// gomapper.Map(\u0026s, \u0026d)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tfmt.Print(dest)\n}\n```\nAuto Route.\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/insei/gomapper\"\n)\n\ntype Source struct {\n\tName string\n\tAge  uint8\n}\n\ntype Dest struct {\n\tNameCustom string\n\tAge        uint8\n}\n\nfunc main() {\n\terr := gomapper.AutoRoute[Source, Dest]()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\ts := Source{\n\t\tName: \"DefaultName\",\n\t\tAge:  16,\n\t}\n\tdest, err := gomapper.MapTo[Dest](s) \n\t// or gomapper.MapTo[Dest](\u0026s)\n\t// or dest := Dest{}\n\t// gomapper.Map(\u0026s, \u0026dest)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tfmt.Print(dest)\n}\n```\nMap structs into slices.\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/insei/gomapper\"\n)\n\ntype Source struct {\n\tName string\n\tAge  uint8\n}\n\ntype Dest struct {\n\tNameCustom string\n\tAge        uint8\n}\n\nfunc main() {\n\terr := gomapper.AutoRoute[Source, Dest]() // or manual\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\ts := Source{\n\t\tName: \"DefaultName\",\n\t\tAge:  16,\n\t}\n\tsSlice := []Source{ s }\n\tsDest, err := gomapper.MapTo[[]Dest](sSlice) \n\t// or sDest := []Dest{}\n\t// sDest, err := gomapper.MapTo(sSlice, \u0026sDest) \n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tfmt.Print(sDest)\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finsei%2Fgomapper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finsei%2Fgomapper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finsei%2Fgomapper/lists"}