jackc / jackc/pgx

Migrate from ERB to Go Templates

Open
#2,199 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
14.3k
Forks
1.1k
Avg merge
6d 9h
Merged PRs (30d)
11

Description

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

1. Identify all ERB templates currently used in the project.
2. Convert each ERB template to an equivalent Go template.
3. 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
```ruby
<% [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:

```go
{{ range $pg_byte_size := .ByteSizes }}
{{ $pg_bit_size := mul $pg_byte_size 8 }}
func TestInt{{ $pg_byte_size }}Codec(t *testing.T) {
// ...
}
{{ end }}
```

### Links

- [Generating code](https://go.dev/blog/generate)
- [text/template](https://pkg.go.dev/text/template)

Contributor guide

Open the contributing guide

Research direction

Start by identifying all ERB templates and the current Rakefile, using int_test.go.erb as the example entry point. Review Go's text/template and code-generation guidance before planning equivalent templates and a Makefile, Taskfile, or script. Done means every ERB template is migrated and the Rakefile-based generation process is replaced.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, ruby
Domain
build-system
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.