List cross-references by wormhole name
This page describes how to list cross-references by wormhole name.
Given a wormhole resource name in the namespaces/{namespace}/{collection}/{id}
format, the service returns the list of all cross-references in which the womrhole entry is an edge.
It is possible to specify the edge's State
( PENDING
, APPROVED
, REJECTED
, PARTIAL
) through the filter to restrict the result set.
Sample
The following sample shows how to list cross-references by wormhole name.
Replace [RESOURCE NAME]
with a valid resource name in the namespaces/{namespace}/{collection}/{id}
format.
tip
State = 1: PENDING
State = 2: APPROVED
State = 3: REJECTED
State = 4: PARTIAL
tip
Tip: do not forget to replace CLIENT-ID
and CLIENT-SECRET
with valid IAM Service Account client credentials.
- Golang
package main
import (
"context"
"log"
"golang.org/x/oauth2/clientcredentials"
"google.golang.org/api/option"
gapic "github.com/animeapis/api-go-client/crossrefs/v1alpha1"
crossref "github.com/animeapis/go-genproto/crossrefs/v1alpha1"
)
var (
WormholeName = "[RESOURCE NAME]"
ClientID = "[CLIENT-ID]"
ClientSecret = "[CLIENT-SECRET]"
)
var (
TokenURL = "https://accounts.animeshon.com/o/oauth2/token"
Endpoint = "crossrefs.animeapis.com:443"
)
func main() {
ctx := context.Background()
config := &clientcredentials.Config{
ClientID: ClientID,
ClientSecret: ClientSecret,
TokenURL: TokenURL,
}
options := []option.ClientOption{
option.WithEndpoint(Endpoint),
option.WithTokenSource(config.TokenSource(ctx)),
}
client, err := gapic.NewReferrerClient(ctx, options...)
if err != nil {
log.Fatalf("NewClient: %s", err)
}
request := &crossref.ListWormholeCrossRefsRequest{
Name: WormholeName,
WithApproved: true,
WithPending: true,
WithPartial: true,
WithRejected: true,
}
wormholes, err := client.ListWormholeCrossRefs(ctx, request)
if nil != err {
log.Fatalf("ListWormholeCrossRefs: %s", err)
}
for _, crossref := range wormholes.GetCrossrefs() {
log.Printf("name : %s", crossref.GetName())
}
}