v1 List schemas (DEPRECATED)

(DEPRECATED) List schemas

Code sample

Go

Before trying this sample, follow the Go setup instructions in the Pub/Sub quickstart using client libraries . For more information, see the Pub/Sub Go API reference documentation .

To authenticate to Pub/Sub, set up Application Default Credentials. For more information, see Set up authentication for a local development environment .

  import 
  
 ( 
  
 "context" 
  
 "fmt" 
  
 "io" 
  
 "cloud.google.com/go/pubsub" 
  
 "google.golang.org/api/iterator" 
 ) 
 func 
  
 listSchemas 
 ( 
 w 
  
 io 
 . 
 Writer 
 , 
  
 projectID 
  
 string 
 ) 
  
 ([] 
 * 
 pubsub 
 . 
  SchemaConfig 
 
 , 
  
 error 
 ) 
  
 { 
  
 // projectID := "my-project-id" 
  
 ctx 
  
 := 
  
 context 
 . 
 Background 
 () 
  
 client 
 , 
  
 err 
  
 := 
  
 pubsub 
 . 
 NewSchemaClient 
 ( 
 ctx 
 , 
  
 projectID 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 return 
  
 nil 
 , 
  
 fmt 
 . 
 Errorf 
 ( 
 "pubsub.NewSchemaClient: %w" 
 , 
  
 err 
 ) 
  
 } 
  
 defer 
  
 client 
 . 
 Close 
 () 
  
 var 
  
 schemas 
  
 [] 
 * 
 pubsub 
 . 
  SchemaConfig 
 
  
 schemaIter 
  
 := 
  
 client 
 . 
  Schemas 
 
 ( 
 ctx 
 , 
  
 pubsub 
 . 
  SchemaViewFull 
 
 ) 
  
 for 
  
 { 
  
 sc 
 , 
  
 err 
  
 := 
  
 schemaIter 
 . 
 Next 
 () 
  
 if 
  
 err 
  
 == 
  
 iterator 
 . 
 Done 
  
 { 
  
 break 
  
 } 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 return 
  
 nil 
 , 
  
 fmt 
 . 
 Errorf 
 ( 
 "schemaIter.Next: %w" 
 , 
  
 err 
 ) 
  
 } 
  
 fmt 
 . 
 Fprintf 
 ( 
 w 
 , 
  
 "Got schema: %#v\n" 
 , 
  
 sc 
 ) 
  
 schemas 
  
 = 
  
 append 
 ( 
 schemas 
 , 
  
 sc 
 ) 
  
 } 
  
 fmt 
 . 
 Fprintf 
 ( 
 w 
 , 
  
 "Got %d schemas" 
 , 
  
 len 
 ( 
 schemas 
 )) 
  
 return 
  
 schemas 
 , 
  
 nil 
 } 
 

Ruby

Before trying this sample, follow the Ruby setup instructions in the Pub/Sub quickstart using client libraries . For more information, see the Pub/Sub Ruby API reference documentation .

To authenticate to Pub/Sub, set up Application Default Credentials. For more information, see Set up authentication for a local development environment .

  pubsub 
  
 = 
  
 Google 
 :: 
 Cloud 
 :: 
  Pubsub 
 
 . 
 new 
 schemas 
  
 = 
  
 pubsub 
 . 
 schemas 
 puts 
  
 "Schemas in project:" 
 schemas 
 . 
 each 
  
 do 
  
 | 
 schema 
 | 
  
 puts 
  
 schema 
 . 
 name 
 end 
 

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser .

Create a Mobile Website
View Site in Mobile | Classic
Share by: