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 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 AvroCFWriter
- type AvroItemWriter
- type BuildArgs
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 AvroCFWriter ¶ added in v0.12.0
type AvroCFWriter interface {
AvroItemWriter
}
type AvroItemWriter ¶ added in v0.12.0
AvroItemWriter 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
GenerateAvro bool
GenerateMessagePack bool
ImportPath string
StructNameMap map[string]string
FieldNameMap map[string]string
}
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 GenerateAvro is a flag that defines if Avro serializing code should be built. 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