Generating Code
As GO is "a bit stiff" when it comes to generic things, we utilize code generation when possible.
The core logic regarding code generation resides within the pkg/codegen
package.
The definitions are provided using YAML files throughout the source; the templates are defined under the pkg/codegen/assets
folder.
Running codegen
You need to remove the old codegen binary whenever the source code changes. The codegen commands will compile the binary if it’s not there. |
make codegen
make watch.codegen
make clean.codegen
Extending existing codegen
Rest API
The codegen generates REST API request handlers and request parsing.
The documentation is generated using the openapi3-converter tool, not codegen. |
-
*/rest.yaml
-
rest_handler.go.tpl
-
rest_request.go.tpl
Types
The codegen generates common type set receivers and generic boilerplate logic for features such as resource labels.
-
*/*/types.yaml
-
type_labels.gen.go.tpl
-
type_set.gen.go.tpl
-
type_set.gen_test.go.tpl
Actions
The codegen generates the available service actions along with the properties and errors. These actions are primarily used for the action log.
-
*/services/*_actions.yaml
-
actions.gen.go.tpl
Events
The codegen generates the available events that the system can emit from different services. These events are primarily used by the event bus for automation.
-
*/service/event/events.yaml
-
events.gen.adoc.tpl
-
events.gen.go.tpl
-
events.go.tpl
Store interface and implementations
The codegen generates the entire store interface. In the case of RDBMS, the implementation is also generated.
-
store/*.yaml
-
store_base.gen.go.tpl
-
store_interfaces_joined.gen.go.tpl
-
store_partials.go.tpl
-
store_rdbms.gen.go.tpl
-
store_test_all.gen.go.tpl
Options
The codegen generates all of the defined options accessible from the .env
file variables.
The options may define defaults as well as any preprocessing.
-
pkg/options/*.yaml
-
options.gen.adoc.tpl
-
options.gen.go.tpl