| /** |
| Example Entity feed for Google Order Redirect. Create "generated" directory for generated proto classes. |
| Download lastest version of protoc from https://github.com/protocolbuffers/protobuf/releases. |
| Generate proto classes with: |
| go install google.golang.org/protobuf/cmd/protoc-gen-go@latest |
| protoc --proto_path=../proto/ --go_out=generated ../proto/entity.proto |
| |
| See https://protobuf.dev/reference/go/go-generated/ for more details. |
| **/ |
| |
| package main |
| |
| import ( |
| pb "feed/app/generated/google/madden/ingestion" |
| "fmt" |
| |
| "google.golang.org/protobuf/encoding/protojson" |
| ) |
| |
| func main() { |
| feedJSON := createFeed() |
| fmt.Println(feedJSON) |
| } |
| |
| func createFeed() string { |
| |
| // Create Entity |
| entity := &pb.Entity{ |
| EntityId: "merchant-id", |
| Name: "Mo's Dinner", |
| Telephone: "+14567891234", |
| Url: "http://moesdinner.com", |
| Location: &pb.GeoCoordinates{ |
| Latitude: 41.525588, |
| Longitude: -90.507067, |
| Addresses: &pb.GeoCoordinates_Address{ |
| Address: &pb.PostalAddress{ |
| Country: "US", |
| Locality: "Mountain View", |
| Region: "CA", |
| PostalCode: "94043", |
| StreetAddress: "1600 Amphitheatre Pkwy", |
| }, |
| }, |
| }, |
| } |
| |
| // Create EntityFeed |
| feed := &pb.EntityFeed{ |
| Data: []*pb.Entity{ |
| entity, |
| }, |
| } |
| |
| // Serialize to JSON string |
| marshalOptions := protojson.MarshalOptions{ |
| UseProtoNames: true, |
| } |
| jsonBytes, _ := marshalOptions.Marshal(feed) |
| return string(jsonBytes) |
| } |