Documentation
¶
Overview ¶
Package generate implements a tooling to generate Golang structs from a JSON schema file. It is intended to be used with the go generate, https://blog.golang.org/generate
Index ¶
- func AvroOptionalTime(t *time.Time) int64
- func AvroOptionalTimeSlice(times []*time.Time) []int64
- func AvroTime(t time.Time) int64
- func AvroTimeSlice(times []time.Time) []int64
- func BuildStructs(schemaPath string, outputDir string, useMessagePack bool) error
- func BuildStructsRename(schemaPath string, outputDir string, useMessagePack bool, ...) error
- func BuildStructsWithArgs(args BuildArgs) error
- type AvroCFDeleter
- type AvroCFWriter
- type BuildArgs
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AvroOptionalTime ¶ added in v0.15.0
AvroOptionalTime converts the given *time.Time into an int64 compatible with an Avro timestamp.millis logical type. It sets the value to 0 if the pointer is nil http://avro.apache.org/docs/current/spec.html#Date
func AvroOptionalTimeSlice ¶ added in v0.15.0
AvroOptionalTimeSlice converts the given []time.Time into a []int64 leveraging AvroTime If the array is empty or all values are nil a nil slice is returned.
func AvroTime ¶ added in v0.12.0
AvroTime converts the given time.Time into an int64 compatible with an Avro timestamp.millis logical type. http://avro.apache.org/docs/current/spec.html#Date
func AvroTimeSlice ¶ added in v0.12.0
AvroTimeSlice converts the given []time.Time into a []int64 leveraging AvroTime.
func BuildStructs ¶
BuildStructs is a backward-compatibility wrapper for BuildStructsWithArgs.
func BuildStructsRename ¶ added in v0.5.13
func BuildStructsRename(schemaPath string, outputDir string, useMessagePack bool, nameMap map[string]string) error
BuildStructsRename is a backward-compatibility wrapper for BuildStructsWithArgs.
func BuildStructsWithArgs ¶ added in v0.6.2
BuildStructsWithArgs takes a JSON Schema and generates Golang structs that match the schema. The generated structs include struct tags for marshaling/unmarshaling to/from JSON. One file will be created for each included allOf/oneOf file in the root schema with any allOf files resulting in structs which are embedded in the oneOf files.
The JSON schema can specify more information than the structs enforce (like field size) and so validation of any JSON generated from the structs is still necessary.
The args parameter is a BuildArgs struct that defines the settings for this function ¶
If undefined args.OutputDir defaults to the current working directory.
The package name is set to the args.OutputDir directory name.
NOTE: If oneOf/allOf entries exist than any JSON schema instances in the root schema file will be skipped.
Types ¶
type AvroCFDeleter ¶ added in v0.12.3
AvroCFDeleter implements functionality to write an Avro Container file with the metadata field AvroDeleted set to true. This is a record that a delete of the given item occurred but is writing a new Container File. This enables adhering to the the Avro Schema for the given data type and tracking history of changes for any given ID.
type AvroCFWriter ¶ added in v0.12.0
AvroCFWriter creates a Avro Container file containing the data from the struct that implements this interface.
type BuildArgs ¶ added in v0.6.2
type BuildArgs struct { SchemaPath string OutputDir string OutputDirGraphQL string DescriptionAsStructTag bool NoNestedStructs bool Pointers bool InterfaceFiles bool GenerateAvro bool GenerateMessagePack bool GenerateGraphQL bool ImportPath string StructNameMap map[string]string FieldNameMap map[string]string GraphQLTypeNameMap map[string]string // Changes the "type ABC" name of GraphQL schema. EmbedAllOf bool ScalarAny bool }
BuildArgs contains information used to build the structs for a JSONschema.
SchemaPath is the path tot he jsonSchema file to use generate the Go struct representations OutputDir is the destination for the generated files NoNestedStructs will create structs that have no unnamed nested structs in them but rather defined types for each nested struct Pointers will create non-required objects and date/time fields with pointers thus allowing the JSON to support null for those fields. InterfaceFiles will create separate files for interface implementations rather than putting them all in the interface file. (GraphQL-only currently.) GenerateAvro is a flag that defines if Avro serializing code should be built. The Avro generated code will only use a single field in the case where a field name is defined in a oneOf and elsewhere in the JSON schema. When converting the most specific version of such a field will be used. In general conflicting names like this should be avoided in the JSON schema. GenerateMessagePack is a flag that defines if message pack serializing code should be built. StructNameMap allows specifying the type name of the struct for each JSON file. FieldNameMap is used to provide alternate names for fields in the resulting structs. The property names in the JSON tags for these structs remains the same as supplied. This can be used to accommodate names that are valid JSON but not valid Go identifiers
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
avro/arrays
Code generated by github.com/actgardner/gogen-avro.
|
Code generated by github.com/actgardner/gogen-avro. |
avro/complex
Code generated by github.com/actgardner/gogen-avro.
|
Code generated by github.com/actgardner/gogen-avro. |
avro/nested
Code generated by github.com/actgardner/gogen-avro/v7.
|
Code generated by github.com/actgardner/gogen-avro/v7. |
avro/repeats
Code generated by github.com/actgardner/gogen-avro.
|
Code generated by github.com/actgardner/gogen-avro. |
avro/simple
Code generated by github.com/actgardner/gogen-avro.
|
Code generated by github.com/actgardner/gogen-avro. |
avro/times
Code generated by github.com/actgardner/gogen-avro.
|
Code generated by github.com/actgardner/gogen-avro. |
avro/timespointers
Code generated by github.com/actgardner/gogen-avro.
|
Code generated by github.com/actgardner/gogen-avro. |
nonest/avro/complex
Code generated by github.com/actgardner/gogen-avro.
|
Code generated by github.com/actgardner/gogen-avro. |
nonest/avro/nested
Code generated by github.com/actgardner/gogen-avro.
|
Code generated by github.com/actgardner/gogen-avro. |
nonest/avro/simple
Code generated by github.com/actgardner/gogen-avro.
|
Code generated by github.com/actgardner/gogen-avro. |
pointers/avro/complex
Code generated by github.com/actgardner/gogen-avro.
|
Code generated by github.com/actgardner/gogen-avro. |
pointers/avro/nested
Code generated by github.com/actgardner/gogen-avro.
|
Code generated by github.com/actgardner/gogen-avro. |
pointers/avro/simple
Code generated by github.com/actgardner/gogen-avro.
|
Code generated by github.com/actgardner/gogen-avro. |
pointers/avro/times
Code generated by github.com/actgardner/gogen-avro.
|
Code generated by github.com/actgardner/gogen-avro. |
generate_test_data
|
|