{"id":20145751,"url":"https://github.com/obsius/govertible","last_synced_at":"2026-05-13T19:33:02.082Z","repository":{"id":57610411,"uuid":"102803976","full_name":"obsius/govertible","owner":"obsius","description":"Golang package to convert similar structs.","archived":false,"fork":false,"pushed_at":"2017-11-02T02:35:07.000Z","size":214,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-11-30T09:51:10.141Z","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/obsius.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":"2017-09-08T01:43:42.000Z","updated_at":"2017-11-02T16:40:09.000Z","dependencies_parsed_at":"2022-09-26T20:02:12.830Z","dependency_job_id":null,"html_url":"https://github.com/obsius/govertible","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/obsius/govertible","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/obsius%2Fgovertible","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/obsius%2Fgovertible/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/obsius%2Fgovertible/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/obsius%2Fgovertible/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/obsius","download_url":"https://codeload.github.com/obsius/govertible/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/obsius%2Fgovertible/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32997647,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-13T13:14:54.681Z","status":"ssl_error","status_checked_at":"2026-05-13T13:14:51.610Z","response_time":115,"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":[],"created_at":"2024-11-13T22:18:01.182Z","updated_at":"2026-05-13T19:33:02.068Z","avatar_url":"https://github.com/obsius.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# govertible\n\n[![godoc](http://img.shields.io/badge/go-documentation-blue.svg?style=flat-square)](https://godoc.org/github.com/obsius/govertible)\n[![coverage](https://coveralls.io/repos/github/obsius/govertible/badge.svg?branch=master)](https://coveralls.io/github/obsius/govertible?branch=master)\n[![go report](https://goreportcard.com/badge/obsius/govertible)](https://goreportcard.com/report/obsius/govertible)\n[![build](https://travis-ci.org/obsius/govertible.svg?branch=master)](https://travis-ci.org/obsius/govertible)\n[![license](http://img.shields.io/badge/license-mit-blue.svg?style=flat-square)](https://raw.githubusercontent.com/obsius/govertible/master/LICENSE)\n\n![govertible](logo.png \"govertible\")\n\nA lightweight package to convert similar structures to and from each other.\n\ngovertible will convert matching fields names of identical types from a source to a destination struct.  `ConvertTo()` and `ConvertFrom()` are implementable and allow for custom conversions as shown in the examples below.\n\n#### ConvertibleTo\n```golang\ntype ConvertibleTo interface {\n\tConvertTo(interface{}) (bool, error)\n}\n```\n\n#### ConvertibleFrom\n```golang\ntype ConvertibleTo interface {\n\tConvertTo(interface{}) (bool, error)\n}\n```\n## Examples\nSimple example converting one struct to another by field names without implementing an interface.\n```golang\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/obsius/govertible\"\n)\n\ntype employee struct {\n\tName  string\n\tPhone []byte\n\tID    uint64\n}\ntype person struct {\n\tName  string\n\tPhone []byte\n\tAge   int\n}\n\nfunc main() {\n\tperson := person{\n\t\tName:  \"El Capitan\",\n\t\tPhone: []byte(\"123-456-7890\"),\n\t\tAge:   20,\n\t}\n\temployee := employee{}\n\n\t// convert a person struct to an employee struct\n\tgovertible.Convert(\u0026person, \u0026employee)\n\n\tfmt.Println(employee)\n}\n```\n\nAdvanced example converting one struct to another using the convertTo interface.\n```golang\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/obsius/govertible\"\n)\n\ntype employee struct {\n\tName  *string\n\tAlias string\n\tPhone []byte\n\tID    uint64\n}\ntype person struct {\n\tName  string\n\tAlias string\n\tPhone []byte\n\tAge   int\n}\n\nfunc (this *person) ConvertTo(val interface{}) (bool, error) {\n\tswitch val.(type) {\n\tcase *employee:\n\t\tv := val.(*employee)\n\t\tgovertible.ConvertFields(this, val)\n\t\tv.ID = uint64(this.Age)\n\t\tbreak\n\t}\n\n\treturn false, nil\n}\n\nfunc main() {\n\tperson := person{\n\t\tName:  \"El Capitan\",\n\t\tAlias: \"The Chief\",\n\t\tPhone: []byte(\"123-456-7890\"),\n\t\tAge:   10,\n\t}\n\temployee := employee{}\n\n\t// convert a person struct to an employee struct\n\tgovertible.Convert(\u0026person, \u0026employee)\n\n\tfmt.Println(employee)\n}\n```\n\nAdvanced example converting one struct to another using the convertFrom interface.\n```golang\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/obsius/govertible\"\n)\n\ntype employee struct {\n\tName  *string\n\tAlias string\n\tPhone []byte\n\tID    uint64\n}\ntype person struct {\n\tName  string\n\tAlias string\n\tPhone []byte\n\tAge   int\n}\n\nfunc (this *employee) ConvertFrom(val interface{}) (bool, error) {\n\tswitch val.(type) {\n\tcase *person:\n\t\tv := val.(*person)\n\t\tgovertible.ConvertFields(val, this)\n\t\tthis.ID = uint64(v.Age)\n\t\tbreak\n\t}\n\n\treturn false, nil\n}\n\nfunc main() {\n\tperson := person{\n\t\tName:  \"El Capitan\",\n\t\tAlias: \"The Chief\",\n\t\tPhone: []byte(\"123-456-7890\"),\n\t\tAge:   10,\n\t}\n\temployee := employee{}\n\n\t// convert a person struct to an employee struct\n\tgovertible.Convert(\u0026person, \u0026employee)\n\n\tfmt.Println(employee)\n}\n```\n\n## Benchmarks\noperation|ns/op|# operations|total time\n-|-|-|-\nConvertStruct|22,850|100k|2.5s","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fobsius%2Fgovertible","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fobsius%2Fgovertible","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fobsius%2Fgovertible/lists"}