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

haoxins/structs-to-schema

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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"
                        }
                    ]
                }
            ]
        }
    ]
}

About

No description or website provided.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages