github.com/hamba/avro@v1.8.0/registry/example_test.go (about)

     1  package registry_test
     2  
     3  import (
     4  	"fmt"
     5  	"log"
     6  
     7  	"github.com/hamba/avro/registry"
     8  )
     9  
    10  func Example() {
    11  	reg, err := registry.NewClient("http://example.com")
    12  	if err != nil {
    13  		log.Fatal(err)
    14  	}
    15  
    16  	schema, err := reg.GetSchema(5)
    17  	if err != nil {
    18  		log.Fatal(err)
    19  	}
    20  
    21  	fmt.Println("schema: ", schema)
    22  
    23  	schemaRaw := `["null","string","int"]`
    24  	id, schema, err := reg.IsRegistered("foobar", schemaRaw)
    25  	if err != nil {
    26  		id, schema, err = reg.CreateSchema("foobar", schemaRaw)
    27  		if err != nil {
    28  			log.Fatal(err)
    29  		}
    30  	}
    31  
    32  	fmt.Println("id: ", id)
    33  	fmt.Println("schema: ", schema)
    34  }