Skip to content
/ go-avro Public

Go library for working with Avro schema and data.

Notifications You must be signed in to change notification settings

arcus/go-avro

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-avro

GoDoc

Go library for working with Avro schema and data.

Usage

Build a record-based Avro schema.

sexEnum := &avro.Enum{
  Name: "sex",
  Symbols: []string{
    "Male",
    "Female",
    "Unknown",
  },
}

participantSchema := &avro.Record{
  Name: "participant",

  Fields: []*avro.Field{
    {
      Name: "id",
      Type: String,
    },
    {
      Name: "birth_date",
      Type: avro.Union{
        avro.Null,
        avro.Date,
      },
    },
    {
      Name: "sex",
      Type: avro.Union{
        avro.Null,
        sexEnum,
      },
    },
  },
}

Marshal schema to JSON-encoded representation.

bytes, err := avro.Marshal(participantSchema)

Unmarshal encoded schema into its native type.

var participantSchema Record
avro.UnmarshalSchema(bytes, &participantSchema)

Integration with the LinkedIn GoAvro library

// SchemaToCodec returns a new goavro.Codec from the provided avro.Schema.
func SchemaToCodec(s avro.Schema) (*goavro.Codec, error) {
	b, err := avro.Marshal(s)
	if err != nil {
		return nil, err
	}
	return goavro.NewCodec(string(b))
}

// CodecToSchema derives an avro.Schema from the provided goavro.Codec.
func CodecToSchema(c *goavro.Codec) (avro.Schema, error) {
	return avro.Unmarshal([]byte(c.Schema()))
}

About

Go library for working with Avro schema and data.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages