Migrate from ERB to Go Templates
I propose to get rid of ERB in favor of native Go templates. Go has powerful generation tools, and it's better to use them.
Motivation
In a Go project, it is generally better to use Go tools for template generation to maintain consistency and leverage the native capabilities of the language. Using Go templates instead of ERB (Embedded Ruby) will:
- Improve maintainability by using a single language for both code and templates.
- Enhance readability for Go developers who may not be familiar with Ruby.
- Simplify the build process by reducing dependencies on external tools.
Tasks
- Identify all ERB templates currently used in the project.
- Convert each ERB template to an equivalent Go template.
- Use Makefile (Taskfile, simple script) instead of Rakefile.
Example of converting one file
int_test.go.erb to int_test.go.tmpl
Current ERB Template
<% [2, 4, 8].each do |pg_byte_size| %>
<% pg_bit_size = pg_byte_size * 8 %>
func TestInt<%= pg_byte_size %>Codec(t *testing.T) {
// ...
}
<% end %>
Equivalent Go Template:
{{ range $pg_byte_size := .ByteSizes }}
{{ $pg_bit_size := mul $pg_byte_size 8 }}
func TestInt{{ $pg_byte_size }}Codec(t *testing.T) {
// ...
}
{{ end }}
Links
While in theory I would prefer to use Go rather than another language and avoid the Ruby dependency, for templates I am not convinced. The erb templates are self-contained. But text/template would need some sort of setup to register the mul function and to pass in .ByteSizes.
Also, in my option, text/template syntax is rather awkward. e.g. pg_byte_size * 8 vs. mul $pg_byte_size 8.