{"id":26053416,"url":"https://github.com/sphere-sh/go-struct-sync","last_synced_at":"2026-06-10T07:31:07.980Z","repository":{"id":281159647,"uuid":"944393190","full_name":"sphere-sh/go-struct-sync","owner":"sphere-sh","description":"A Go package for comparing struct instances and applying detected changes.","archived":false,"fork":false,"pushed_at":"2025-03-07T10:07:55.000Z","size":12,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-06-10T06:39:15.291Z","etag":null,"topics":["data-structures","golang","sphere","structures","sync"],"latest_commit_sha":null,"homepage":"https://www.sphere.sh/","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sphere-sh.png","metadata":{"files":{"readme":"README.md","changelog":"change/change.go","contributing":null,"funding":null,"license":null,"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}},"created_at":"2025-03-07T09:16:02.000Z","updated_at":"2025-03-11T14:06:28.000Z","dependencies_parsed_at":"2025-03-07T10:37:06.256Z","dependency_job_id":null,"html_url":"https://github.com/sphere-sh/go-struct-sync","commit_stats":null,"previous_names":["sphere-sh/go-struct-sync"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/sphere-sh/go-struct-sync","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sphere-sh%2Fgo-struct-sync","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sphere-sh%2Fgo-struct-sync/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sphere-sh%2Fgo-struct-sync/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sphere-sh%2Fgo-struct-sync/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sphere-sh","download_url":"https://codeload.github.com/sphere-sh/go-struct-sync/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sphere-sh%2Fgo-struct-sync/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34142637,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-10T02:00:07.152Z","response_time":89,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["data-structures","golang","sphere","structures","sync"],"created_at":"2025-03-08T07:28:24.218Z","updated_at":"2026-06-10T07:31:07.957Z","avatar_url":"https://github.com/sphere-sh.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GO Struct Compare\nA Go package for comparing struct instances and applying detected changes.\n\n\n### Installation\n```bash\ngo get github.com/sphere-sh/go-struct-sync\n````\n\n## Overview\nThis package provides utilities to:\n- Compare two structs and detect differences (added, modified, or deleted fields)\n- Apply a set of changes to a struct\n- Filter, merge, and manipulate change sets\n- Convert changes to human-readable format or JSON\n\n## Usage\n\n### Basic Comparison\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"github.com/sphere-sh/go-struct-sync/compare\"\n)\n\nfunc main() {\n    type Person struct {\n        Name    string\n        Age     int\n        Address string\n        Active  bool\n    }\n\n    // Original struct\n    old := Person{\n        Name:    \"John Doe\",\n        Age:     30,\n        Address: \"123 Main St\", \n        Active:  true,\n    }\n\n    // Modified struct\n    new := Person{\n        Name:    \"John Doe\",\n        Age:     31,\n        Address: \"456 Oak Ave\",\n        Active:  false,\n    }\n\n    // Compare the structs\n    changes, err := compare.CompareStructs(old, new)\n    if err != nil {\n        fmt.Printf(\"Error: %v\\n\", err)\n        return\n    }\n\n    // Print the changes\n    fmt.Println(compare.FormatChanges(changes))\n}\n```\n\n### Applying Changes\n\n```go\nimport (\n\"github.com/sphere-sh/go-struct-sync/change\"\n)\n\n// Apply changes to the original struct\nresult, err := change.ApplyChanges(old, changes)\nif err != nil {\n    fmt.Printf(\"Error applying changes: %v\\n\", err)\n    return\n}\n\n// Cast to the correct type\nmodifiedPerson := result.(Person)\nfmt.Printf(\"Modified person: %+v\\n\", modifiedPerson)\n```\n\n### Filtering Changes\n\n```go\nimport (\n\"github.com/sphere-sh/go-struct-sync/compare\"\n)\n\n// Get only modified fields\nmodifiedChanges := compare.FilterChanges(\n    changes, \n    []change.ChangeType{change.Modified}, \n    nil,\n)\n\n// Get only changes to specific fields\naddressChanges := compare.FilterChanges(\n    changes, \n    nil, \n    []string{\"Address\"},\n)\n```\n\n### Working with Change Maps\n\n```go\nimport (\n\"github.com/sphere-sh/go-struct-sync/compare\"\n)\n\n// Convert changes to map for efficient lookup\nchangeMap := compare.ChangesToMap(changes)\n\n// Get change for specific field\naddressChange, exists := changeMap[\"Address\"]\nif exists {\n    fmt.Printf(\"Address changed from %v to %v\\n\", addressChange.OldValue, addressChange.NewValue)\n}\n```\n\n## API Reference\n\n### Types\n\n```go\ntype ChangeType int\n\nconst (\n    Modified ChangeType = iota\n    Added\n    Deleted\n)\n\ntype Change struct {\n    Field      string\n    ChangeType ChangeType\n    OldValue   interface{}\n    NewValue   interface{}\n}\n```\n\n### Functions\n\n```go\n// Compares two structs and returns a list of changes\nfunc CompareStructs(old, new interface{}) ([]Change, error)\n\n// Applies a list of changes to a struct\nfunc ApplyChanges(original interface{}, changes []Change) (interface{}, error)\n\n// Filters changes by type and/or field name\nfunc FilterChanges(changes []Change, changeTypes []ChangeType, fields []string) []Change\n\n// Converts a list of changes to a map keyed by field name\nfunc ChangesToMap(changes []Change) map[string]Change\n\n// Merges multiple change lists, with later changes taking precedence\nfunc MergeChanges(changeLists ...[]Change) []Change\n\n// Returns a human-readable representation of changes\nfunc FormatChanges(changes []Change) string\n\n// Serializes changes to JSON\nfunc ChangesToJSON(changes []Change) ([]byte, error)\n\n// Deserializes changes from JSON\nfunc ChangesFromJSON(data []byte) ([]Change, error)\n\n// Creates a new change list that would undo the given changes\nfunc RevertChanges(changes []Change) []Change\n```\n\n## License\nMIT License\n\n## Contributing\nContributions are welcome! Please feel free to submit a Pull Request.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsphere-sh%2Fgo-struct-sync","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsphere-sh%2Fgo-struct-sync","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsphere-sh%2Fgo-struct-sync/lists"}