Skip to content

nryanov/schemakeeper-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Schemakeeper-go

Build Status Coverage Status GitHub license

This is a golang-client for schemakeeper.

Install

go dep github.com/nryanov/schemakeeper-go 0.2.0

Usage

package main

import (
    "fmt"
    "github.com/linkedin/goavro/v2"
    "github.com/nryanov/schemakeeper-go"
)

func main() {
    codec, err := goavro.NewCodec(`{"type": "record","name": "test","fields" : [{"name": "f1", "type": "long"},{"name": "f2", "type": ["null", "string"]}]}`)
    if err != nil {
        fmt.Println(err)
    }

	cfg := schemakeepergo.CreateConfiguration("host:port")
	client := schemakeepergo.CreateCachedSchemaKeeperClient(cfg)

	serializer := schemakeepergo.CreateAvroSerializer(cfg, client)
	deserializer := schemakeepergo.CreateAvroDeserializer(cfg, client)

	value := make(map[string]interface{})
	value["f1"] = int64(1)
	value["f2"] = goavro.Union("string", "value")
	
    data, err := serializer.Serialize("subjectName", value, codec)
    if err != nil {
        fmt.Println(err)
    }

	record, err := deserializer.Deserialize(data)
	if err != nil {
		fmt.Println(err)
	}

    fmt.Println(record)
}

Limitations

Currently, this client supports only avro serialization/deserialization.