{"id":22885498,"url":"https://github.com/djboris9/merger","last_synced_at":"2025-07-24T22:07:54.334Z","repository":{"id":57491190,"uuid":"77785093","full_name":"djboris9/merger","owner":"djboris9","description":"Go package that merges different datatypes together","archived":false,"fork":false,"pushed_at":"2017-12-17T16:11:36.000Z","size":14,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-06T23:13:50.815Z","etag":null,"topics":["data-structures","golang","golang-library","golang-package","map","merge","slice","struct"],"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/djboris9.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-01-01T15:45:16.000Z","updated_at":"2022-05-12T10:19:41.000Z","dependencies_parsed_at":"2022-08-29T20:31:58.277Z","dependency_job_id":null,"html_url":"https://github.com/djboris9/merger","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/djboris9%2Fmerger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/djboris9%2Fmerger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/djboris9%2Fmerger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/djboris9%2Fmerger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/djboris9","download_url":"https://codeload.github.com/djboris9/merger/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246516990,"owners_count":20790331,"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":["data-structures","golang","golang-library","golang-package","map","merge","slice","struct"],"created_at":"2024-12-13T19:47:58.907Z","updated_at":"2025-03-31T18:27:37.524Z","avatar_url":"https://github.com/djboris9.png","language":"Go","readme":"# Merger\nThis Go package merges different types together. Nested types will be merged too.\nThis can be useful for:\n\n* Merging configurations from different sources\n* Deduplicate items before serialization\n* Setting field preferences\n\nIt works with Go 1.7 and greater\n\n## Usage\nDocumentation with examples is available on https://godoc.org/github.com/djboris9/merger\nThis readme is only an introduction.\n\n### Merge algorithm\nLet A be the first arbitrary value and B be the second arbitrary value with precedence.\nboolean, numeric and string types will be overwritten by the argument with precedence (B).\nslice and array types will be concatenated (A ∥ B).\nstruct and map types will be merged together giving a union of all fields, where the values of them are merged too (A ∪ B)\n\n### Example\nFull usage example:\n```Go\npackage main\n\nimport (\n\t\"encoding/json\"\n\t\"fmt\"\n\t\"log\"\n\n\t\"github.com/djboris9/merger\"\n)\n\nfunc main() {\n\tA := struct {\n\t\tFieldA string\n\t\tFieldB string\n\t\tFieldC []int\n\t}{\n\t\t\"aAaA\",\n\t\t\"bBbB\",\n\t\t[]int{1, 2},\n\t}\n\n\tB := struct {\n\t\tFieldA string\n\t\tFieldC []int\n\t}{\n\t\t\"NewVal\",\n\t\t[]int{3, 4},\n\t}\n\n\t// Merge struct A and B together\n\tV, err := merger.Merge(A, B)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\t// Print it\n\tser, _ := json.Marshal(V)\n\tfmt.Println(string(ser))\n\t// Output: {\"FieldA\":\"NewVal\",\"FieldB\":\"bBbB\",\"FieldC\":[1,2,3,4]}\n}\n```\n\nMerging maps:\n```Go\nA := map[string]int{\n\t\"x\": 1,\n\t\"y\": 2,\n}\nB := map[string]int{\n\t\"a\": 1,\n\t\"b\": 2,\n}\nV, _ := merger.Merge(A, B)\n// V: map[string]int{\"a\": 1, \"b\": 2, \"x\": 1, \"y\": 2}\n```\n\nMerging slices:\n```Go\nA := []int{1, 2, 3}\nB := []int{4, 5, 6}\nV, _ := merger.Merge(A, B)\n// V: []int{1, 2, 3, 4, 5}\n```\n\nOther examples are in the godoc.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdjboris9%2Fmerger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdjboris9%2Fmerger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdjboris9%2Fmerger/lists"}