in analytics-hub/snippets/create_listing_golang/main.go [266:309]
func create_or_get_listing(ctx context.Context, client *analyticshub.Client, projectID, location, exchangeID, listingID string, restrictEgress bool, sharedDataset 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{}
if restrictEgress {
restrictedExportConfig.Enabled = true
restrictedExportConfig.RestrictDirectTableAccess = true
restrictedExportConfig.RestrictQueryResult = true
} else {
restrictedExportConfig.Enabled = false
restrictedExportConfig.RestrictDirectTableAccess = false
restrictedExportConfig.RestrictQueryResult = false
}
req := &analyticshubpb.CreateListingRequest{
Parent: fmt.Sprintf("projects/%s/locations/%s/dataExchanges/%s", projectID, location, exchangeID),
ListingId: listingID,
Listing: &analyticshubpb.Listing{
DisplayName: "Example Exchange Listing - created using golang API",
Description: "Example Exchange Listing - created using golang API",
Categories: []analyticshubpb.Listing_Category{
analyticshubpb.Listing_CATEGORY_OTHERS,
},
Source: &analyticshubpb.Listing_BigqueryDataset{
BigqueryDataset: &analyticshubpb.Listing_BigQueryDatasetSource{
Dataset: fmt.Sprintf("projects/%s/datasets/%s", projectID, sharedDataset),
},
},
RestrictedExportConfig: restrictedExportConfig,
},
}
resp, err := client.CreateListing(ctx, req)
if err != nil {
println(err.Error())
return nil, err
}
return resp, nil
} else {
return resp, nil
}
}