Skip to content
This repository has been archived by the owner on Mar 18, 2024. It is now read-only.

Latest commit

 

History

History
104 lines (94 loc) · 2.65 KB

README.md

File metadata and controls

104 lines (94 loc) · 2.65 KB

Build Status Badge Go Docs Badge

From Golang Structs to Schema

  • Avro (Avsc)
type Event struct {
  ClientIP  string  `avro:"clientIP"`
  SessionId string  `avro:"sessionId"`
  Payload   Payload `avro:"payload"`
}

type Payload struct {
  Type     string        `avro:"type"`
  Target   EventTarget   `avro:"target"`
  Position EventPosition `avro:"position"`
}

type EventTarget struct {
  Type        string `avro:"type"`
  TagName     string `avro:"tagName"`
  TextContent string `avro:"textContent"`
  Link        string `avro:"link"`
}

type EventPosition struct {
  PageX int32 `avro:"pageX"`
  PageY int32 `avro:"pageY"`
}

schema, err := ParseAvro(Event{})
  • The schema will be
{
    "name":"Event",
    "type":"record",
    "fields":[
        {
            "name":"clientIP",
            "type":"string"
        },
        {
            "name":"sessionId",
            "type":"string"
        },
        {
            "name":"payload",
            "type":"record",
            "fields":[
                {
                    "name":"type",
                    "type":"string"
                },
                {
                    "name":"target",
                    "type":"record",
                    "fields":[
                        {
                            "name":"type",
                            "type":"string"
                        },
                        {
                            "name":"tagName",
                            "type":"string"
                        },
                        {
                            "name":"textContent",
                            "type":"string"
                        },
                        {
                            "name":"link",
                            "type":"string"
                        }
                    ]
                },
                {
                    "name":"position",
                    "type":"record",
                    "fields":[
                        {
                            "name":"pageX",
                            "type":"int"
                        },
                        {
                            "name":"pageY",
                            "type":"int"
                        }
                    ]
                }
            ]
        }
    ]
}