{"id":19775683,"url":"https://github.com/kfelter/protobuf-example","last_synced_at":"2025-04-30T19:30:37.810Z","repository":{"id":65389445,"uuid":"363311187","full_name":"kfelter/protobuf-example","owner":"kfelter","description":"simple example demonstrating how to use protobuf in golang","archived":false,"fork":false,"pushed_at":"2023-08-26T14:37:18.000Z","size":218,"stargazers_count":9,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-06T04:08:18.419Z","etag":null,"topics":["example","golang","proto3","protobuf"],"latest_commit_sha":null,"homepage":"","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/kfelter.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-05-01T03:07:29.000Z","updated_at":"2025-02-14T12:07:22.000Z","dependencies_parsed_at":"2024-06-20T14:04:54.139Z","dependency_job_id":"10f30660-6498-4b21-b284-c9472308e237","html_url":"https://github.com/kfelter/protobuf-example","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/kfelter%2Fprotobuf-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kfelter%2Fprotobuf-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kfelter%2Fprotobuf-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kfelter%2Fprotobuf-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kfelter","download_url":"https://codeload.github.com/kfelter/protobuf-example/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251769206,"owners_count":21640862,"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":["example","golang","proto3","protobuf"],"created_at":"2024-11-12T05:17:11.479Z","updated_at":"2025-04-30T19:30:37.516Z","avatar_url":"https://github.com/kfelter.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# protobuf example\nA simple example of using protobuf in golang\n\n# Summary\nIf you are not using gRPC for server to server communications in your golang app, you are missing out on one of the best optimizations that you can make for the performance of the code and the development team.\n\n1. It makes understanding the data model easier by strictly enforcing the proto 3 syntax. Json is easy to get started with and make a prototype, but protobuf will be more strict about syntax and standardize your communication between services.\n\n2. Updating the schema for a gRPC request is simple, update the protobuf file and run code generation. Then it becomes like using any other package written in go to call your external service. No more boilerplate client code.\n\n3. Protobuf marshaling is faster, uses less memory and produces a smaller payload than Json or xml Marshalling. This directly impacts infrastructure costs and will save money.\n\nThe time and cost savings you will see from using gRPC in your golang app is worth the time investment it will take to learn and implement it.\n\n# creating data structures using protobuf\nwrite the protobuf file\n```proto\nsyntax = \"proto3\";\npackage publish;\noption go_package  = \"/publish\";\n\nmessage Event {\n  bytes content = 1;\n  repeated string tags = 2;\n}\n\nmessage EventList {\n  repeated Event events = 1;\n}\n```\n\nThis creates two structs, one is an event struct that contains `content` that is a byte array and `tags` that is a string array of strings\nThere is also a struct for an array of events.\n\nNow run the protoc command to generate the go code we will use in `main.go`\n```\nprotoc --proto_path=. --go_out=. publish.proto\n```\nThis creates the directory `publish` that contains the package `publish` with the go code that we can import to our `main.go` file.\n\nNow we can import it using `github.com/kfelter/protobuf-example/publish`\n\nThere are other advantages to using protobuf that can be found in the protobuf documentation.\n\nReferences:\n\ninstall protoc           https://grpc.io/docs/protoc-installation/\n\nproto3 language guide    https://developers.google.com/protocol-buffers/docs/proto3#simple\n\nprotobuf golang tutorial https://developers.google.com/protocol-buffers/docs/gotutorial\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkfelter%2Fprotobuf-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkfelter%2Fprotobuf-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkfelter%2Fprotobuf-example/lists"}