sr

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

README

Schema Registry utils

This project depends on the srclient and extends its functionality.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Employee = Schemas{
	ParentSchema: `{
		"type": "record",
		"name": "Employee",
		"namespace": "com.company.hr",
		"fields": [
			{"name": "personalInfo", "type": "PersonalInfo"},
			{"name": "department", "type": "string"},
			{"name": "role", "type": "string"},
			{"name": "yearsOfExperience", "type": "int"}
		]
	}`,

	ChildSchemas: map[string]string{
		"PersonalInfo": `{
			"type": "record",
			"name": "PersonalInfo",
			"namespace": "com.company.hr",
			"fields": [
				{"name": "name", "type": "string"},
				{"name": "age", "type": "int"},
				{"name": "address", "type": "string"}
			]
		}`,
	},
	ExpectedSchema: `{
		"type": "record",
		"name": "Employee",
		"namespace": "com.company.hr",
		"fields": [
			{
				"name": "personalInfo", 
				"type": {
					"type": "record",
					"name": "PersonalInfo",
					"namespace": "com.company.hr",
					"fields": [
						{"name": "name", "type": "string"},
						{"name": "age", "type": "int"},
						{"name": "address", "type": "string"}
					]
				}
			},
			{"name": "department", "type": "string"},
			{"name": "role", "type": "string"},
			{"name": "yearsOfExperience", "type": "int"}
		]
	}
	`,
}

* * * TEST SCHEMA *

View Source
var User = Schemas{
	ParentSchema: `{
		"type": "record",
		"name": "User",
		"namespace": "com.example",
		"fields": [
			{"name": "headers", "type": "Headers"},
			{"name": "things", "type": "Things"},
			{"name": "name", "type": "string"},
			{"name": "age",  "type": "int"}
		]
	}`,

	ChildSchemas: map[string]string{
		"Headers": `{
			"type": "record",
			"name": "Headers",
			"namespace": "com.example",
			"fields": [
				{"name": "headerName", "type": "string"},
				{"name": "headerAge",  "type": "int"}
			]
		}`,
		"Things": `{
			"type": "record",
			"name": "Things",
			"namespace": "com.example",
			"fields": [
				{"name": "stuff", "type": "string"}
			]
		}`,
	},

	ExpectedSchema: `{
		"type": "record",
		"name": "User",
		"namespace": "com.example",
		"fields": [
			{"name": "headers", 
			"type": {
				"type": "record",
				"name": "Headers",
				"namespace": "com.example",
				"fields": [
					{"name": "headerName", "type": "string"},
					{"name": "headerAge",  "type": "int"}
				]
			}},
			{"name": "things", "type": {
				"type": "record",
				"name": "Things",
				"namespace": "com.example",
				"fields": [
					{"name": "stuff", "type": "string"}
				]
			}},
			{"name": "name", "type": "string"},
			{"name": "age",  "type": "int"}
		]
	}`,
}

* * * ORIGINAL TEST SCHEMA *

Functions

func MergeSchemas

func MergeSchemas(parentSchema string, childSchemas map[string]string) (string, error)

MergeSchemas takes a parent schema and a map of child schemas and returns a combined schema

func New

func New(url string) (*sr, error)

NewSchemaRegistryClient creates a new schema registry client

Types

type AvroSchema

type AvroSchema struct {
	Type      string  `json:"type"`
	Name      string  `json:"name"`
	Namespace string  `json:"namespace"`
	Fields    []Field `json:"fields"`
}

type Field

type Field struct {
	Name string      `json:"name"`
	Type interface{} `json:"type"`
}

type Schemas

type Schemas struct {
	ParentSchema   string
	ChildSchemas   map[string]string
	ExpectedSchema string
}

Schemas holds the JSON strings for parent and child schemas.

Jump to

Keyboard shortcuts

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