registry

package
v1.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 15, 2021 License: MIT Imports: 11 Imported by: 5

Documentation

Overview

Package registry implements a Confluent Schema Registry compliant client.

See the Confluent Schema Registry docs for an understanding of the API: https://docs.confluent.io/current/schema-registry/docs/api.html

Example
package main

import (
	"fmt"
	"log"

	"github.com/hamba/avro/registry"
)

func main() {
	reg, err := registry.NewClient("http://example.com")
	if err != nil {
		log.Fatal(err)
	}

	schema, err := reg.GetSchema(5)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println("schema: ", schema)

	schemaRaw := `["null","string","int"]`
	id, schema, err := reg.IsRegistered("foobar", schemaRaw)
	if err != nil {
		id, schema, err = reg.CreateSchema("foobar", schemaRaw)
		if err != nil {
			log.Fatal(err)
		}
	}

	fmt.Println("id: ", id)
	fmt.Println("schema: ", schema)
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is an HTTP registry client.

func NewClient

func NewClient(baseURL string, opts ...ClientFunc) (*Client, error)

NewClient creates a schema registry Client with the given base url.

func (*Client) CreateSchema

func (c *Client) CreateSchema(subject, schema string) (int, avro.Schema, error)

CreateSchema creates a schema in the registry, returning the schema id.

func (*Client) GetLatestSchema

func (c *Client) GetLatestSchema(subject string) (avro.Schema, error)

GetLatestSchema gets the latest schema for a subject.

func (*Client) GetLatestSchemaInfo added in v1.2.0

func (c *Client) GetLatestSchemaInfo(subject string) (SchemaInfo, error)

GetLatestSchemaInfo gets the latest schema and schema metadata for a subject.

func (*Client) GetSchema

func (c *Client) GetSchema(id int) (avro.Schema, error)

GetSchema returns the schema with the given id.

GetSchema will cache the schema in memory after it is successfully returned, allowing it to be used efficiently in a high load situation.

func (*Client) GetSchemaByVersion

func (c *Client) GetSchemaByVersion(subject string, version int) (avro.Schema, error)

GetSchemaByVersion gets the schema by version.

func (*Client) GetSubjects

func (c *Client) GetSubjects() ([]string, error)

GetSubjects gets the registry subjects.

func (*Client) GetVersions

func (c *Client) GetVersions(subject string) ([]int, error)

GetVersions gets the schema versions for a subject.

func (*Client) IsRegistered

func (c *Client) IsRegistered(subject, schema string) (int, avro.Schema, error)

IsRegistered determines of the schema is registered.

type ClientFunc

type ClientFunc func(*Client)

ClientFunc is a function used to customize the Client.

func WithBasicAuth added in v0.7.0

func WithBasicAuth(username, password string) ClientFunc

WithBasicAuth sets the credentials to perform http basic auth.

func WithHTTPClient

func WithHTTPClient(client *http.Client) ClientFunc

WithHTTPClient sets the http client to make requests with.

type Error

type Error struct {
	StatusCode int `json:"-"`

	Code    int    `json:"error_code"`
	Message string `json:"message"`
}

Error is returned by the registry when there is an error.

func (Error) Error

func (e Error) Error() string

Error returns the error message.

type Registry

type Registry interface {
	// GetSchema returns the schema with the given id.
	GetSchema(id int) (avro.Schema, error)

	// GetSubjects gets the registry subjects.
	GetSubjects() ([]string, error)

	// GetVersions gets the schema versions for a subject.
	GetVersions(subject string) ([]int, error)

	// GetSchemaByVersion gets the schema by version.
	GetSchemaByVersion(subject string, version int) (avro.Schema, error)

	// GetLatestSchema gets the latest schema for a subject.
	GetLatestSchema(subject string) (avro.Schema, error)

	// GetLatestSchemaInfo gets the latest schema and schema metadata for a subject.
	GetLatestSchemaInfo(subject string) (SchemaInfo, error)

	// CreateSchema creates a schema in the registry, returning the schema id.
	CreateSchema(subject, schema string) (int, avro.Schema, error)

	// IsRegistered determines of the schema is registered.
	IsRegistered(subject, schema string) (int, avro.Schema, error)
}

Registry represents a schema registry.

type SchemaInfo added in v1.2.0

type SchemaInfo struct {
	Schema  avro.Schema
	ID      int
	Version int
}

SchemaInfo represents a schema and metadata information.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL