structstoschema

package module
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 6, 2023 License: MIT Imports: 2 Imported by: 0

README

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

Documentation

Index

Constants

View Source
const (
	AvroTypeRecord = "record"
	AvroTypeString = "string"
	AvroTypeBool   = "boolean"
	AvroTypeInt32  = "int"
	AvroTypeInt64  = "long"
	AvroTypeFloat  = "float"
	AvroTypeDouble = "double"
)

Variables

This section is empty.

Functions

func ParseAvro

func ParseAvro(in any) (string, error)

Types

type Element

type Element struct {
	Name     string
	Type     string
	Children []Element
}

func ParseAvroElements

func ParseAvroElements(t reflect.Type) []Element

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL