{"id":16777000,"url":"https://github.com/rueian/gogo-struct-codec","last_synced_at":"2026-05-10T17:16:34.170Z","repository":{"id":37038569,"uuid":"214704329","full_name":"rueian/gogo-struct-codec","owner":"rueian","description":"codec of the Well Known google.protobuf.Struct type which generated by gogo protobuf","archived":false,"fork":false,"pushed_at":"2022-11-08T07:23:12.000Z","size":29,"stargazers_count":1,"open_issues_count":1,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-23T05:29:17.414Z","etag":null,"topics":["bson","codec","gogo","golang","json","mongo","protobuf"],"latest_commit_sha":null,"homepage":null,"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/rueian.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-10-12T19:35:18.000Z","updated_at":"2021-11-10T08:19:51.000Z","dependencies_parsed_at":"2023-01-20T11:02:35.574Z","dependency_job_id":null,"html_url":"https://github.com/rueian/gogo-struct-codec","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rueian%2Fgogo-struct-codec","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rueian%2Fgogo-struct-codec/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rueian%2Fgogo-struct-codec/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rueian%2Fgogo-struct-codec/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rueian","download_url":"https://codeload.github.com/rueian/gogo-struct-codec/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243911660,"owners_count":20367725,"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":["bson","codec","gogo","golang","json","mongo","protobuf"],"created_at":"2024-10-13T07:11:35.215Z","updated_at":"2026-05-10T17:16:34.106Z","avatar_url":"https://github.com/rueian.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gogo-struct-codec\n\ncodec of the Well Known `google.protobuf.Struct` type which generated by [gogo protobuf](https://github.com/gogo/protobuf)\n\n## Drop-in replacement for gogo's `types.Struct`\n\nThe `ptypes.Struct` is provided as a drop-in replacement for the gogo's `types.Struct` which doesn't be implemented with common Marshal/Unmarshal interfaces.\n\nCurrently `ptypes.Struct` is implemented by embedding gogo's `types.Struct` and with the following interfaces:\n\n* `json.Marshaler` and `json.Unmarshaler` (by gogo's `jsonpb`)\n* `sql.Scanner` and `sql/driver.Valuer` (by gogo's `jsonpb`)\n* `bson.Marshaler` and `bson.Unmarshaler` (by `structbson`)\n\n### Drop-in example\n\nPlease take [./example](./example) a look.\n\n```proto\nsyntax = \"proto3\";\npackage example;\n\nimport \"google/protobuf/struct.proto\";\n\nmessage MyMessage {\n    google.protobuf.Struct payload = 1;\n}\n```\n\nAnd please take [./example/gen.sh](./example/gen.sh) a look as well. There is how to tell the gogo output plugin to replace the `Struct` with our one.\n```shell script\n./gen.sh\n```\n\n## BSON Codec\n\nConvert the gogo's `types.Struct` from and to [bson](https://github.com/mongodb/mongo-go-driver)\n\n### MongoDB example\n\n```go\npackage main\n\nimport (\n    \"context\"\n    \"github.com/gogo/protobuf/types\"\n    \"github.com/rueian/gogo-struct-codec/structbson\"\n    \"go.mongodb.org/mongo-driver/bson\"\n    \"go.mongodb.org/mongo-driver/mongo\"\n)\n\nfunc main() {\n    \n    // MUST first replace bson's DefaultRegistry with the one in structbson\n    bson.DefaultRegistry = structbson.DefaultRegistry\n\n    s := types.Struct{Fields:map[string]*types.Value{\n        \"_id\": {Kind: \u0026types.Value_StringValue{StringValue: \"str\"}},\n    }}\n    \n    // connect mongoclient\n\n    res, err := mongoclient.Database(\"db\").Collection(\"collection\").InsertOne(ctx, s)\n    \n    // handle err and response \n}\n```\n\n### BSON manipulation\n\n[more details in test cases](./structbson/main_test.go)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frueian%2Fgogo-struct-codec","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frueian%2Fgogo-struct-codec","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frueian%2Fgogo-struct-codec/lists"}