| /** |
| Example Action 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/action.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 ActionDetail |
| // Example using one link for both delivery and takeout |
| merchantNameCombined := "merchant-1" |
| linkIDCombined := "merchant-1-takeout-delivery-action" |
| urlCombined := "http://provider.com/merchant-1" |
| actionCombined := &pb.ActionDetail{ |
| EntityId: &merchantNameCombined, |
| LinkId: &linkIDCombined, |
| Url: &urlCombined, |
| Actions: []*pb.Action{{ |
| ActionInfo: &pb.Action_FoodOrderingInfo{ |
| FoodOrderingInfo: &pb.FoodOrderingInfo{ |
| ServiceType: pb.FoodOrderingInfo_DELIVERY, |
| }, |
| }}, { |
| ActionInfo: &pb.Action_FoodOrderingInfo{ |
| FoodOrderingInfo: &pb.FoodOrderingInfo{ |
| ServiceType: pb.FoodOrderingInfo_TAKEOUT, |
| }, |
| }}, |
| }, |
| } |
| |
| // Example using a separate link for delivery |
| merchantNameDelivery := "merchant-2" |
| linkIDDelivery := "merchant-2-delivery-action" |
| urlDelivery := "http://provider.com/merchant-2/delivery" |
| actionDelivery := &pb.ActionDetail{ |
| EntityId: &merchantNameDelivery, |
| LinkId: &linkIDDelivery, |
| Url: &urlDelivery, |
| Actions: []*pb.Action{{ |
| ActionInfo: &pb.Action_FoodOrderingInfo{ |
| FoodOrderingInfo: &pb.FoodOrderingInfo{ |
| ServiceType: pb.FoodOrderingInfo_DELIVERY, |
| }, |
| }}, |
| }, |
| } |
| |
| // Create ActionFeed |
| feed := &pb.ActionFeed{ |
| Data: []*pb.ActionDetail{ |
| actionCombined, |
| actionDelivery, |
| }, |
| } |
| |
| // Serialize to JSON string |
| marshalOptions := protojson.MarshalOptions{ |
| UseProtoNames: true, |
| } |
| jsonBytes, _ := marshalOptions.Marshal(feed) |
| return string(jsonBytes) |
| } |
| |
| // [END create_feed] |