go-gorm / go-gorm/cli

refactor: drop `_` prefix and `Interface` suffix from generated types

Open
#50 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
108
Forks
15
PR merge metrics
No merged PRs in 30d

Description

## Summary

The code generator produces types with a leading `_` prefix and an `Interface` suffix:

```go
type _QueryInterface[T any] interface { ... }
type _QueryImpl[T any] struct { ... }
```

Two issues:

1. **`_` prefix** — In Go, `_` is the blank identifier. Using it as a name prefix is non-standard and confuses readers into thinking the variable/type is discarded.
2. **`Interface` suffix** — Per Go convention, interfaces are named after the behavior they describe (e.g. `io.Reader`, not `io.ReaderInterface`).

## Proposed

```go
type Query[T any] interface { ... }
type QueryImpl[T any] struct { ... }
```

Since generated code is in the same package as the constructor `func Query[T any](...)`, the unexported interface name `queryIface` or similar would also work if name clashes are a concern.

## Root Cause

- `internal/gen/generator.go:611` — `IfaceName: "_" + n.Name.Name`
- `internal/gen/template.go` — uses `{{$IfaceName}}Interface` and `{{$IfaceName}}Impl`

## Affected

All generated output files. The template in `internal/gen/template.go` and the naming logic in `internal/gen/generator.go` need updating.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.