{"id":13414124,"url":"https://github.com/ulule/deepcopier","last_synced_at":"2025-03-14T20:31:09.538Z","repository":{"id":35385579,"uuid":"39649008","full_name":"ulule/deepcopier","owner":"ulule","description":"simple struct copying for golang","archived":false,"fork":false,"pushed_at":"2020-04-30T08:31:45.000Z","size":88,"stargazers_count":447,"open_issues_count":7,"forks_count":57,"subscribers_count":22,"default_branch":"master","last_synced_at":"2024-07-31T20:53:34.559Z","etag":null,"topics":[],"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/ulule.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":"2015-07-24T18:01:01.000Z","updated_at":"2024-07-29T03:26:47.000Z","dependencies_parsed_at":"2022-07-08T14:31:15.655Z","dependency_job_id":null,"html_url":"https://github.com/ulule/deepcopier","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/ulule%2Fdeepcopier","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ulule%2Fdeepcopier/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ulule%2Fdeepcopier/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ulule%2Fdeepcopier/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ulule","download_url":"https://codeload.github.com/ulule/deepcopier/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243642088,"owners_count":20323954,"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":[],"created_at":"2024-07-30T20:01:58.339Z","updated_at":"2025-03-14T20:31:09.166Z","avatar_url":"https://github.com/ulule.png","language":"Go","readme":"# Deepcopier\n\n[![Build Status](https://secure.travis-ci.org/ulule/deepcopier.svg?branch=master)](http://travis-ci.org/ulule/deepcopier)\n\nThis package is meant to make copying of structs to/from others structs a bit easier.\n\n## Installation\n\n```bash\ngo get -u github.com/ulule/deepcopier\n```\n\n## Usage\n\n```golang\n// Deep copy instance1 into instance2\nCopy(instance1).To(instance2)\n\n// Deep copy instance1 into instance2 and passes the following context (which\n// is basically a map[string]interface{}) as first argument\n// to methods of instance2 that defined the struct tag \"context\".\nCopy(instance1).WithContext(map[string]interface{}{\"foo\": \"bar\"}).To(instance2)\n\n// Deep copy instance2 into instance1\nCopy(instance1).From(instance2)\n\n// Deep copy instance2 into instance1 and passes the following context (which\n// is basically a map[string]interface{}) as first argument\n// to methods of instance1 that defined the struct tag \"context\".\nCopy(instance1).WithContext(map[string]interface{}{\"foo\": \"bar\"}).From(instance2)\n```\n\nAvailable options for `deepcopier` struct tag:\n\n| Option    | Description                                                          |\n| --------- | -------------------------------------------------------------------- |\n| `field`   | Field or method name in source instance                              |\n| `skip`    | Ignores the field                                                    |\n| `context` | Takes a `map[string]interface{}` as first argument (for methods)     |\n| `force`   | Set the value of a `sql.Null*` field (instead of copying the struct) |\n\n**Options example:**\n\n```golang\ntype Source struct {\n    Name                         string\n    SkipMe                       string\n    SQLNullStringToSQLNullString sql.NullString\n    SQLNullStringToString        sql.NullString\n\n}\n\nfunc (Source) MethodThatTakesContext(c map[string]interface{}) string {\n    return \"whatever\"\n}\n\ntype Destination struct {\n    FieldWithAnotherNameInSource      string         `deepcopier:\"field:Name\"`\n    SkipMe                            string         `deepcopier:\"skip\"`\n    MethodThatTakesContext            string         `deepcopier:\"context\"`\n    SQLNullStringToSQLNullString      sql.NullString \n    SQLNullStringToString             string         `deepcopier:\"force\"`\n}\n\n```\n\nExample:\n\n```golang\npackage main\n\nimport (\n    \"fmt\"\n \n    \"github.com/ulule/deepcopier\"\n)\n\n// Model\ntype User struct {\n    // Basic string field\n    Name  string\n    // Deepcopier supports https://golang.org/pkg/database/sql/driver/#Valuer\n    Email sql.NullString\n}\n\nfunc (u *User) MethodThatTakesContext(ctx map[string]interface{}) string {\n    // do whatever you want\n    return \"hello from this method\"\n}\n\n// Resource\ntype UserResource struct {\n    DisplayName            string `deepcopier:\"field:Name\"`\n    SkipMe                 string `deepcopier:\"skip\"`\n    MethodThatTakesContext string `deepcopier:\"context\"`\n    Email                  string `deepcopier:\"force\"`\n\n}\n\nfunc main() {\n    user := \u0026User{\n        Name: \"gilles\",\n        Email: sql.NullString{\n            Valid: true,\n            String: \"gilles@example.com\",\n        },\n    }\n\n    resource := \u0026UserResource{}\n\n    deepcopier.Copy(user).To(resource)\n\n    fmt.Println(resource.DisplayName)\n    fmt.Println(resource.Email)\n}\n```\n\nLooking for more information about the usage?\n\nWe wrote [an introduction article](https://github.com/ulule/deepcopier/blob/master/examples/rest-usage/README.rst).\nHave a look and feel free to give us your feedback.\n\n## Contributing\n\n* Ping us on twitter [@oibafsellig](https://twitter.com/oibafsellig), [@thoas](https://twitter.com/thoas)\n* Fork the [project](https://github.com/ulule/deepcopier)\n* Help us improving and fixing [issues](https://github.com/ulule/deepcopier/issues)\n\nDon't hesitate ;)\n","funding_links":[],"categories":["Utilities","Reflection","Go","公用事业公司","工具库`可以提升效率的通用代码库和工具`","實用工具","Utility","工具库","实用工具"],"sub_categories":["Utility/Miscellaneous","HTTP Clients","实用程序/Miscellaneous","查询语","Fail injection","Advanced Console UIs","高級控制台界面","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e","交流","高级控制台界面","HTTP客户端"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fulule%2Fdeepcopier","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fulule%2Fdeepcopier","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fulule%2Fdeepcopier/lists"}