Create a custom Record

Record is the interface provided by Baker to represent an “object” of data

As you can read in the Record and LogLine page, Baker processes objects called records. A Record, in Baker, is an interface that provides an abstraction over a record of flattened data, where columns of fields are indexed through integers. If the Record implementations provided by Baker doesn’t fit your needs, you can create your own version, implementing the Record inteface.

How to use your Record implementation

Once your Record implementation is ready, you want to let Baker know how to create new instances of it. To do so, you should create and fill a baker.Components struct. The only required field to set is the CreateRecord, which returns a new instance of your custom record struct. (see more details at CreateRecord).

comp := baker.Components{
	CreateRecord: func() baker.Record {
		return &MyCustomRecord{}
	},

	// ... other configuration
}

The other configuration of the baker.Components, namely Validation, FieldByName, and FieldNames, could be configured also through the TOML configuration. Although, if your own record needs a more specific implementation you can implement them using compiled Go code, see FieldByName, FieldNames, Validation documentation.

Record conformance test

test_helper.go provides a test helper, RecordConformanceTest, one can and should use to verify their custom Record satisfies the invariants required for any Record implementation.

Just pass to RecordConformanceTest a factory function creating new instances of your Record.

Last modified October 29, 2020