Documentation
¶
Overview ¶
Package gen allows generating Go structs from avro schemas.
Index ¶
- func Struct(s string, w io.Writer, cfg Config) error
- func StructFromSchema(schema avro.Schema, w io.Writer, cfg Config) error
- type Config
- type Generator
- type LogicalType
- type OptsFunc
- func WithEncoders(b bool) OptsFunc
- func WithFullName(b bool) OptsFunc
- func WithFullSchema(b bool) OptsFunc
- func WithInitialisms(ss []string) OptsFunc
- func WithLogicalType(logicalType LogicalType) OptsFunc
- func WithMetadata(m any) OptsFunc
- func WithPackageDoc(text string) OptsFunc
- func WithStrictTypes(b bool) OptsFunc
- func WithTemplate(template string) OptsFunc
- type TagStyle
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct {
PackageName string
Tags map[string]TagStyle
FullName bool
Encoders bool
FullSchema bool
StrictTypes bool
Initialisms []string
LogicalTypes []LogicalType
Metadata any
}
Config configures the code generation.
type Generator ¶ added in v2.4.0
type Generator struct {
// contains filtered or unexported fields
}
Generator generates Go structs from schemas.
func NewGenerator ¶ added in v2.4.0
NewGenerator returns a generator.
func (*Generator) ParseWithMetadata ¶ added in v2.29.0
ParseWithMetadata parses an avro schema into Go types with arbitrary metadata attached. The metadata is then passed to the template as `Typedefs[].Metadata`.
type LogicalType ¶ added in v2.25.0
type LogicalType struct {
// Name of the LogicalType
Name string
// Typ returned, has to be a valid Go type
Typ string
// Import added as import (if not empty)
Import string
// ThirdPartyImport added as import (if not empty)
ThirdPartyImport string
}
LogicalType used when the name of the "LogicalType" field in the Avro schema matches the Name attribute.
type OptsFunc ¶ added in v2.15.0
type OptsFunc func(*Generator)
OptsFunc is a function that configures a generator.
func WithEncoders ¶ added in v2.15.0
WithEncoders configures the generator to generate schema and encoders on all objects.
func WithFullName ¶ added in v2.15.0
WithFullName configures the generator to use the full name of a record when creating the struct name.
func WithFullSchema ¶ added in v2.26.0
WithFullSchema configures the generator to store the full schema within the generation context.
func WithInitialisms ¶ added in v2.16.0
WithInitialisms configures the generator to use additional custom initialisms when styling struct and field names.
func WithLogicalType ¶ added in v2.25.0
func WithLogicalType(logicalType LogicalType) OptsFunc
WithLogicalType registers a LogicalType which takes precedence over the default logical types defined by this package.
func WithMetadata ¶ added in v2.28.0
WithMetadata configures the generator to store the metadata within the generation context.
func WithPackageDoc ¶ added in v2.23.0
WithPackageDoc configures the generator to output the given text as a package doc comment.
func WithStrictTypes ¶ added in v2.22.0
WithStrictTypes configures the generator to use strict type sizes.
func WithTemplate ¶ added in v2.22.0
WithTemplate configures the generator to use a custom template provided by the user.
type TagStyle ¶
type TagStyle string
TagStyle defines the styling for a tag.
const ( // Original is a style like whAtEVer_IS_InthEInpuT. Original TagStyle = "original" // Snake is a style like im_written_in_snake_case. Snake TagStyle = "snake" // Camel is a style like imWrittenInCamelCase. Camel TagStyle = "camel" // Kebab is a style like im-written-in-kebab-case. Kebab TagStyle = "kebab" // UpperCamel is a style like ImWrittenInUpperCamel. UpperCamel TagStyle = "upper-camel" )