You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
heetch / avro Public
Avro codec and code generation for Go
Notifications You must be signed in to change notification settings
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Go to fileThis package provides both a code generator that generates Go data structures from Avro schemas and a mapping between native Go data types and Avro schemas. The API is modelled after that of Go's standard library encoding/json package. The documentation can be found here. It also provides support for encoding and decoding messages using an Avro schema registry - see github.com/heetch/avro/avroregistry.
If a definition has a go.package annotation the type from that package will be used instead of generating a Go type. The type must be compatible with the Avro schema (it may contain extra fields, but all fields in common must be compatible).
If a definition has a go.name annotation the associated string will be used for the generated Go type name.
github.com/linkedin/goavro/v2, is oriented towards dynamic processing of Avro data. It does not provide an idiomatic way to marshal/unmarshal Avro data into Go struct values. It does, however, provide good support for encoding and decoding with the standard Avro JSON format, which this package does not.
github.com/actgardner/gogen-avro was the original inspiration for this package. It generates Go code for Avro schemas. It uses a neat VM-based schema for encoding and decoding (and is also used by this package under the hood), but the generated Go data structures are awkward to use and don't reflect the data structures that people would idiomatically define in Go.
For example, in gogen-avro the Avro type ["null", "int"] (either null or an integer) is represented as a struct containing three members, and an associated enum type:
type UnionNullIntTypeEnum int const ( UnionNullIntTypeEnumNull UnionNullIntTypeEnum = 0 UnionNullIntTypeEnumInt UnionNullIntTypeEnum = 1 ) type UnionNullInt struct < Null *types.NullVal Int int32 UnionType UnionNullIntTypeEnum >
With heetch/avro , the above type is simply represented as a *int , a representation likely to be familiar to most Go users.
A github.com/heetch/avro/avroregistrytest package is provided to run integration test against a real schema registry.
import "github.com/heetch/avro/avroregistrytest" type X struct < A int > avroregistrytest.Register(context.Background(), t, A<>, "test-topic")
This code snippet register an avro type for X struct for test-topic in the schema registry defined by KAFKA_REGISTRY_ADDR environment variable that must set to host:port form.