in analytics-hub/snippets/create_listing_golang/main.go [219:263]
func create_or_get_dcr_listing(ctx context.Context, client *analyticshub.Client, projectID, location, exchangeID, listingID string, sharedDataset string, sourceView string) (*analyticshubpb.Listing, error) {
getReq := &analyticshubpb.GetListingRequest{
Name: fmt.Sprintf("projects/%s/locations/%s/dataExchanges/%s/listings/%s", projectID, location, exchangeID, listingID),
}
resp, err := client.GetListing(ctx, getReq)
if err != nil {
println(err.Error())
restrictedExportConfig := &analyticshubpb.Listing_RestrictedExportConfig{}
restrictedExportConfig.Enabled = true
restrictedExportConfig.RestrictDirectTableAccess = true
restrictedExportConfig.RestrictQueryResult = false
req := &analyticshubpb.CreateListingRequest{
Parent: fmt.Sprintf("projects/%s/locations/%s/dataExchanges/%s", projectID, location, exchangeID),
ListingId: listingID,
Listing: &analyticshubpb.Listing{
DisplayName: sourceView,
Categories: []analyticshubpb.Listing_Category{
analyticshubpb.Listing_CATEGORY_OTHERS,
},
PrimaryContact: "primary@contact.co",
Source: &analyticshubpb.Listing_BigqueryDataset{
BigqueryDataset: &analyticshubpb.Listing_BigQueryDatasetSource{
Dataset: fmt.Sprintf("projects/%s/datasets/%s", projectID, sharedDataset),
SelectedResources: []*analyticshubpb.Listing_BigQueryDatasetSource_SelectedResource{
{
Resource: &analyticshubpb.Listing_BigQueryDatasetSource_SelectedResource_Table{
Table: fmt.Sprintf("projects/%s/datasets/%s/tables/%s", projectID, sharedDataset, sourceView),
},
},
},
},
},
RestrictedExportConfig: restrictedExportConfig,
},
}
resp, err := client.CreateListing(ctx, req)
if err != nil {
println(err.Error())
return nil, err
}
return resp, nil
} else {
return resp, nil
}
}