Skip to content

A Simple PoC in Go using Protobuf: Repeated and OneOf

Notifications You must be signed in to change notification settings

donwellus/go-protobuf-oneof

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A Simple PoC in Go using Protobuf: Repeated and OneOf

This Protobuf PoC illustrates the use of a repeated field where its value can have different data structures. For that we use a proto message with a repeated field of another proto message that use a field with an oneof.

It was used Buf CLI to generate Go Code from Protobuf, Buf also has a linter and formatter that was used in Protobuf files.

Diagram

flowchart TB;
    Collection[Collection struct]-- has a list of pointers to -->Item[Item struct];
    Item-- contains -->isItem_Item[isItem_Item interface];
    Item_ShowcaseItem[Item_ShowcaseItem struct] & Item_ProductItem[Item_ProductItem struct] -- implements -->isItem_Item;
    Item_ProductItem-- has a pointer to -->Item_Product[Item_Product struct]
    Item_ShowcaseItem-- has a pointer to -->Item_Showcase[Item_Showcase struct]
Loading

Proto

syntax = "proto3";

package item.v2;
option go_package = "github.com/donwellus/go-protobuf-oneof/proto";

message Item {
  message Product {
    string sku = 1;
  }

  message Showcase {
    string pos = 1;
    string category = 2;
    string slug = 3;
  }

  oneof item {
    Product product_item = 1;
    Showcase showcase_item = 2;
  }
}

message Collection {
  repeated Item items = 1;
}

Getting Started

Clone the repo, walk through the code and execute it: go run main.go

A oneof cannot be repeated =P

About

A Simple PoC in Go using Protobuf: Repeated and OneOf

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages