{"id":37224462,"url":"https://github.com/practo/srclient","last_synced_at":"2026-01-15T01:41:47.407Z","repository":{"id":57542800,"uuid":"288695850","full_name":"practo/srclient","owner":"practo","description":"Golang Client for Schema Registry","archived":false,"fork":true,"pushed_at":"2020-08-19T10:05:01.000Z","size":819,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-06-20T06:29:46.513Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"riferrei/srclient","license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/practo.png","metadata":{"files":{"readme":"README.adoc","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-08-19T09:57:26.000Z","updated_at":"2024-03-31T15:57:25.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/practo/srclient","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/practo/srclient","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/practo%2Fsrclient","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/practo%2Fsrclient/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/practo%2Fsrclient/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/practo%2Fsrclient/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/practo","download_url":"https://codeload.github.com/practo/srclient/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/practo%2Fsrclient/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28441031,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-15T00:55:22.719Z","status":"ssl_error","status_checked_at":"2026-01-15T00:55:20.945Z","response_time":107,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-01-15T01:41:46.572Z","updated_at":"2026-01-15T01:41:47.393Z","avatar_url":"https://github.com/practo.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"= Schema Registry Client for Go\n:toc:\n\n:imagesdir: images/\nimage::Gopher_Dropping_Mic.png[Gopher, 150, 150, float=\"left\"]\n\n*srclient* is a Golang client for https://www.confluent.io/confluent-schema-registry/[Schema Registry], a software that provides a RESTful interface for developers to define standard schemas for their events, share them across the organization and safely evolve them in a way that is backward compatible and future proof.\nUsing this client allows developers to build Golang programs that write and read schema compatible records to/from https://kafka.apache.org/[Apache Kafka] using https://avro.apache.org/[Avro], https://developers.google.com/protocol-buffers[Protobuf], and https://json-schema.org[JSON Schemas] while Schema Registry is used to manage the schemas used.\nUsing this architecture, producers programs interact with Schema Registry to retrieve schemas and use it to serialize records, and then consumer programs can retrieve the same schema from Schema Registry to deserialize the records.\nYou can read more about the benefits of using Schema Registry https://www.confluent.io/blog/schemas-contracts-compatibility[here].\n\n== Features\n\n* *Simple to Use* - This client provides a very high-level abstraction over the operations that developers writing programs for Apache Kafka typically need.\nThus, it will feel natural for them using the functions that this client provides.\nMoreover, developers don't need to handle low-level HTTP details to communicate with Schema Registry.\n* *Performance* - This client provides caching capabilities.\nThis means that any data retrieved from Schema Registry can be cached locally to improve the performance of subsequent requests.\nThis allows programs that are not co-located with Schema Registry to reduce the latency necessary on each request.\nThis functionality can be disabled programmatically.\n* *Confluent Cloud* - Go developers using https://www.confluent.io/confluent-cloud/[Confluent Cloud] can use this client to interact with the fully managed Schema Registry, which provides important features like schema enforcement that enable teams to reduce deployment issues by governing the schema changes as they evolve.\n\n*License*: http://www.apache.org/licenses/LICENSE-2.0[Apache License v2.0]\n\n== Installation\n\nModule install:\n\nThis client is a Go module, therefore you can have it simply by adding the following import to your code:\n\n[source,golang]\n----\nimport \"github.com/riferrei/srclient\"\n----\n\nThen run a build to have this client automatically added to your go.mod file as a dependency.\n\nManual install:\n\n[source,bash]\n----\ngo get -u github.com/riferrei/srclient\n----\n\n== Examples\n\n.Producer\n[source,golang]\n----\nimport (\n\t\"encoding/binary\"\n\t\"encoding/json\"\n\t\"fmt\"\n\t\"io/ioutil\"\n\n\t\"github.com/google/uuid\"\n\t\"github.com/riferrei/srclient\"\n\t\"gopkg.in/confluentinc/confluent-kafka-go.v1/kafka\"\n)\n\ntype ComplexType struct {\n\tID   int    `json:\"id\"`\n\tName string `json:\"name\"`\n}\n\nfunc main() {\n\n\ttopic := \"myTopic\"\n\n\t// 1) Create the producer as you would normally do using Confluent's Go client\n\tp, err := kafka.NewProducer(\u0026kafka.ConfigMap{\"bootstrap.servers\": \"localhost\"})\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tdefer p.Close()\n\n\tgo func() {\n\t\tfor event := range p.Events() {\n\t\t\tswitch ev := event.(type) {\n\t\t\tcase *kafka.Message:\n\t\t\t\tmessage := ev\n\t\t\t\tif ev.TopicPartition.Error != nil {\n\t\t\t\t\tfmt.Printf(\"Error delivering the message '%s'\\n\", message.Key)\n\t\t\t\t} else {\n\t\t\t\t\tfmt.Printf(\"Message '%s' delivered successfully!\\n\", message.Key)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}()\n\n\t// 2) Fetch the latest version of the schema, or create a new one if it is the first\n\tschemaRegistryClient := srclient.CreateSchemaRegistryClient(\"http://localhost:8081\")\n\tschema, err := schemaRegistryClient.GetLatestSchema(topic, false)\n\tif schema == nil {\n\t\tschemaBytes, _ := ioutil.ReadFile(\"complexType.avsc\")\n\t\tschema, err = schemaRegistryClient.CreateSchema(topic, string(schemaBytes), srclient.Avro, false)\n\t\tif err != nil {\n\t\t\tpanic(fmt.Sprintf(\"Error creating the schema %s\", err))\n\t\t}\n\t}\n\tschemaIDBytes := make([]byte, 4)\n\tbinary.BigEndian.PutUint32(schemaIDBytes, uint32(schema.ID()))\n\n\t// 3) Serialize the record using the schema provided by the client,\n\t// making sure to include the schema id as part of the record.\n\tnewComplexType := ComplexType{ID: 1, Name: \"Gopher\"}\n\tvalue, _ := json.Marshal(newComplexType)\n\tnative, _, _ := schema.Codec().NativeFromTextual(value)\n\tvalueBytes, _ := schema.Codec().BinaryFromNative(nil, native)\n\n\tvar recordValue []byte\n\trecordValue = append(recordValue, byte(0))\n\trecordValue = append(recordValue, schemaIDBytes...)\n\trecordValue = append(recordValue, valueBytes...)\n\n\tkey, _ := uuid.NewUUID()\n\tp.Produce(\u0026kafka.Message{\n\t\tTopicPartition: kafka.TopicPartition{\n\t\t\tTopic: \u0026topic, Partition: kafka.PartitionAny},\n\t\tKey: []byte(key.String()), Value: recordValue}, nil)\n\n\tp.Flush(15 * 1000)\n\n}\n----\n\n.Consumer\n[source,golang]\n----\nimport (\n\t\"encoding/binary\"\n\t\"fmt\"\n\n\t\"github.com/riferrei/srclient\"\n\t\"gopkg.in/confluentinc/confluent-kafka-go.v1/kafka\"\n)\n\nfunc main() {\n\n\t// 1) Create the consumer as you would\n\t// normally do using Confluent's Go client\n\tc, err := kafka.NewConsumer(\u0026kafka.ConfigMap{\n\t\t\"bootstrap.servers\": \"localhost\",\n\t\t\"group.id\":          \"myGroup\",\n\t\t\"auto.offset.reset\": \"earliest\",\n\t})\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tc.SubscribeTopics([]string{\"myTopic\", \"^aRegex.*[Tt]opic\"}, nil)\n\n\t// 2) Create a instance of the client to retrieve the schemas for each message\n\tschemaRegistryClient := srclient.CreateSchemaRegistryClient(\"http://localhost:8081\")\n\n\tfor {\n\t\tmsg, err := c.ReadMessage(-1)\n\t\tif err == nil {\n\t\t\t// 3) Recover the schema id from the message and use the\n\t\t\t// client to retrieve the schema from Schema Registry.\n\t\t\t// Then use it to deserialize the record accordingly.\n\t\t\tschemaID := binary.BigEndian.Uint32(msg.Value[1:5])\n\t\t\tschema, err := schemaRegistryClient.GetSchema(int(schemaID))\n\t\t\tif err != nil {\n\t\t\t\tpanic(fmt.Sprintf(\"Error getting the schema with id '%d' %s\", schemaID, err))\n\t\t\t}\n\t\t\tnative, _, _ := schema.Codec().NativeFromBinary(msg.Value[5:])\n\t\t\tvalue, _ := schema.Codec().TextualFromNative(nil, native)\n\t\t\tfmt.Printf(\"Here is the message %s\\n\", string(value))\n\t\t} else {\n\t\t\tfmt.Printf(\"Error consuming the message: %v (%v)\\n\", err, msg)\n\t\t}\n\t}\n\n\tc.Close()\n\t\n}\n----\n\nBoth examples have been created using https://github.com/confluentinc/confluent-kafka-go[Confluent's Golang for Apache Kafka^TM^].\n\n== Confluent Cloud\n\nTo use this client with https://www.confluent.io/confluent-cloud/[Confluent Cloud] you will need the endpoint of your managed Schema Registry and an API Key/Secret.\nBoth can be easily retrieved from the Confluent Cloud UI once you select an environment:\n\nimage::Getting_Endpoint_and_APIKeys.png[]\n\nFinally, your Go program need to provide this information to the client:\n\n[source,golang]\n----\nschemaRegistryClient := srclient.CreateSchemaRegistryClient(\"https://prefix.us-east-2.aws.confluent.cloud\")\nschemaRegistryClient.SetCredentials(\"apiKey\", \"apiSecret\")\n----\n\n== Acknowledgements\n\n* Apache, Apache Kafka, Kafka, and associated open source project names are trademarks of the https://www.apache.org/[Apache Software Foundation].\n* The https://blog.golang.org/gopher[Go Gopher], is an artistic creation of http://reneefrench.blogspot.com/[Renee French].","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpracto%2Fsrclient","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpracto%2Fsrclient","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpracto%2Fsrclient/lists"}