From 5ce320c4bc9fe91016acd313c3f1e181727c300a Mon Sep 17 00:00:00 2001 From: Beni Pranata Date: Mon, 5 Oct 2026 15:13:54 +0700 Subject: [PATCH 1/2] shiftgen: use j.MKV for structured logging in generated code Replace j.KV(count, n) with j.MKV{count: n} in the generated Update method's ErrRowCount wrap so the key/value is emitted as structured log metadata. --- shiftgen/template.go | 2 +- shiftgen/testdata/case_basic/shift_gen.go.golden | 4 ++-- shiftgen/testdata/case_basic_string/shift_gen.go.golden | 4 ++-- shiftgen/testdata/case_special_names/shift_gen.go.golden | 4 ++-- shiftgen/testdata/case_specify_times/shift_gen.go.golden | 2 +- shiftgen/testdata/case_version/shift_gen.go.golden | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/shiftgen/template.go b/shiftgen/template.go index 2e9edb4..c6d5ecb 100644 --- a/shiftgen/template.go +++ b/shiftgen/template.go @@ -94,7 +94,7 @@ func (一 {{.Type}}) Update( return {{.IDZeroValue}}, err } if n != 1 { - return {{.IDZeroValue}}, errors.Wrap(shift.ErrRowCount, "{{.Type}}", j.KV("count", n)) + return {{.IDZeroValue}}, errors.Wrap(shift.ErrRowCount, "{{.Type}}", j.MKV{"count", n}) } return 一.ID, nil diff --git a/shiftgen/testdata/case_basic/shift_gen.go.golden b/shiftgen/testdata/case_basic/shift_gen.go.golden index 4acd21f..9016c57 100644 --- a/shiftgen/testdata/case_basic/shift_gen.go.golden +++ b/shiftgen/testdata/case_basic/shift_gen.go.golden @@ -78,7 +78,7 @@ func (一 update) Update( return 0, err } if n != 1 { - return 0, errors.Wrap(shift.ErrRowCount, "update", j.KV("count", n)) + return 0, errors.Wrap(shift.ErrRowCount, "update", j.MKV{"count", n}) } return 一.ID, nil @@ -110,7 +110,7 @@ func (一 complete) Update( return 0, err } if n != 1 { - return 0, errors.Wrap(shift.ErrRowCount, "complete", j.KV("count", n)) + return 0, errors.Wrap(shift.ErrRowCount, "complete", j.MKV{"count", n}) } return 一.ID, nil diff --git a/shiftgen/testdata/case_basic_string/shift_gen.go.golden b/shiftgen/testdata/case_basic_string/shift_gen.go.golden index 96617ad..477d1da 100644 --- a/shiftgen/testdata/case_basic_string/shift_gen.go.golden +++ b/shiftgen/testdata/case_basic_string/shift_gen.go.golden @@ -73,7 +73,7 @@ func (一 update) Update( return "", err } if n != 1 { - return "", errors.Wrap(shift.ErrRowCount, "update", j.KV("count", n)) + return "", errors.Wrap(shift.ErrRowCount, "update", j.MKV{"count", n}) } return 一.ID, nil @@ -105,7 +105,7 @@ func (一 complete) Update( return "", err } if n != 1 { - return "", errors.Wrap(shift.ErrRowCount, "complete", j.KV("count", n)) + return "", errors.Wrap(shift.ErrRowCount, "complete", j.MKV{"count", n}) } return 一.ID, nil diff --git a/shiftgen/testdata/case_special_names/shift_gen.go.golden b/shiftgen/testdata/case_special_names/shift_gen.go.golden index fdf6d64..3798331 100644 --- a/shiftgen/testdata/case_special_names/shift_gen.go.golden +++ b/shiftgen/testdata/case_special_names/shift_gen.go.golden @@ -79,7 +79,7 @@ func (一 변수) Update( return 0, err } if n != 1 { - return 0, errors.Wrap(shift.ErrRowCount, "변수", j.KV("count", n)) + return 0, errors.Wrap(shift.ErrRowCount, "변수", j.MKV{"count", n}) } return 一.ID, nil @@ -121,7 +121,7 @@ func (一 エラー) Update( return 0, err } if n != 1 { - return 0, errors.Wrap(shift.ErrRowCount, "エラー", j.KV("count", n)) + return 0, errors.Wrap(shift.ErrRowCount, "エラー", j.MKV{"count", n}) } return 一.ID, nil diff --git a/shiftgen/testdata/case_specify_times/shift_gen.go.golden b/shiftgen/testdata/case_specify_times/shift_gen.go.golden index 53d7acb..667df99 100644 --- a/shiftgen/testdata/case_specify_times/shift_gen.go.golden +++ b/shiftgen/testdata/case_specify_times/shift_gen.go.golden @@ -110,7 +110,7 @@ func (一 uFoo) Update( return 0, err } if n != 1 { - return 0, errors.Wrap(shift.ErrRowCount, "uFoo", j.KV("count", n)) + return 0, errors.Wrap(shift.ErrRowCount, "uFoo", j.MKV{"count", n}) } return 一.ID, nil diff --git a/shiftgen/testdata/case_version/shift_gen.go.golden b/shiftgen/testdata/case_version/shift_gen.go.golden index a5788f0..f3cd00c 100644 --- a/shiftgen/testdata/case_version/shift_gen.go.golden +++ b/shiftgen/testdata/case_version/shift_gen.go.golden @@ -72,7 +72,7 @@ func (一 update) Update( return 0, err } if n != 1 { - return 0, errors.Wrap(shift.ErrRowCount, "update", j.KV("count", n)) + return 0, errors.Wrap(shift.ErrRowCount, "update", j.MKV{"count", n}) } return 一.ID, nil From 1922d8a2628ccc23622026632f574bf2cd0e79dc Mon Sep 17 00:00:00 2001 From: Beni Pranata Date: Mon, 5 Oct 2026 15:50:51 +0700 Subject: [PATCH 2/2] key fix --- shiftgen/template.go | 8 ++++---- shiftgen/testdata/case_basic/shift_gen.go.golden | 4 ++-- shiftgen/testdata/case_basic_string/shift_gen.go.golden | 4 ++-- shiftgen/testdata/case_special_names/shift_gen.go.golden | 4 ++-- shiftgen/testdata/case_specify_times/shift_gen.go.golden | 2 +- shiftgen/testdata/case_version/shift_gen.go.golden | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/shiftgen/template.go b/shiftgen/template.go index c6d5ecb..687e844 100644 --- a/shiftgen/template.go +++ b/shiftgen/template.go @@ -16,8 +16,8 @@ import ( {{ range .Inserters }} -// Insert inserts a new {{.Table}} table entity. All the fields of the -// {{.Type}} receiver are set, as well as status, created_at and updated_at. +// Insert inserts a new {{.Table}} table entity. All the fields of the +// {{.Type}} receiver are set, as well as status, created_at and updated_at. // The newly created entity id is returned on success or an error. func (一 {{.Type}}) Insert( ctx context.Context, tx *sql.Tx, st shift.Status, @@ -59,7 +59,7 @@ func (一 {{.Type}}) Insert( } {{end}}{{ range .Updaters }} // Update updates the status of a {{.Table}} table entity. All the fields of the -// {{.Type}} receiver are updated, as well as status and updated_at. +// {{.Type}} receiver are updated, as well as status and updated_at. // The entity id is returned on success or an error. func (一 {{.Type}}) Update( ctx context.Context, tx *sql.Tx, from shift.Status, to shift.Status, @@ -94,7 +94,7 @@ func (一 {{.Type}}) Update( return {{.IDZeroValue}}, err } if n != 1 { - return {{.IDZeroValue}}, errors.Wrap(shift.ErrRowCount, "{{.Type}}", j.MKV{"count", n}) + return {{.IDZeroValue}}, errors.Wrap(shift.ErrRowCount, "{{.Type}}", j.MKV{"count": n}) } return 一.ID, nil diff --git a/shiftgen/testdata/case_basic/shift_gen.go.golden b/shiftgen/testdata/case_basic/shift_gen.go.golden index 9016c57..27e3087 100644 --- a/shiftgen/testdata/case_basic/shift_gen.go.golden +++ b/shiftgen/testdata/case_basic/shift_gen.go.golden @@ -78,7 +78,7 @@ func (一 update) Update( return 0, err } if n != 1 { - return 0, errors.Wrap(shift.ErrRowCount, "update", j.MKV{"count", n}) + return 0, errors.Wrap(shift.ErrRowCount, "update", j.MKV{"count": n}) } return 一.ID, nil @@ -110,7 +110,7 @@ func (一 complete) Update( return 0, err } if n != 1 { - return 0, errors.Wrap(shift.ErrRowCount, "complete", j.MKV{"count", n}) + return 0, errors.Wrap(shift.ErrRowCount, "complete", j.MKV{"count": n}) } return 一.ID, nil diff --git a/shiftgen/testdata/case_basic_string/shift_gen.go.golden b/shiftgen/testdata/case_basic_string/shift_gen.go.golden index 477d1da..81aac01 100644 --- a/shiftgen/testdata/case_basic_string/shift_gen.go.golden +++ b/shiftgen/testdata/case_basic_string/shift_gen.go.golden @@ -73,7 +73,7 @@ func (一 update) Update( return "", err } if n != 1 { - return "", errors.Wrap(shift.ErrRowCount, "update", j.MKV{"count", n}) + return "", errors.Wrap(shift.ErrRowCount, "update", j.MKV{"count": n}) } return 一.ID, nil @@ -105,7 +105,7 @@ func (一 complete) Update( return "", err } if n != 1 { - return "", errors.Wrap(shift.ErrRowCount, "complete", j.MKV{"count", n}) + return "", errors.Wrap(shift.ErrRowCount, "complete", j.MKV{"count": n}) } return 一.ID, nil diff --git a/shiftgen/testdata/case_special_names/shift_gen.go.golden b/shiftgen/testdata/case_special_names/shift_gen.go.golden index 3798331..b96c36c 100644 --- a/shiftgen/testdata/case_special_names/shift_gen.go.golden +++ b/shiftgen/testdata/case_special_names/shift_gen.go.golden @@ -79,7 +79,7 @@ func (一 변수) Update( return 0, err } if n != 1 { - return 0, errors.Wrap(shift.ErrRowCount, "변수", j.MKV{"count", n}) + return 0, errors.Wrap(shift.ErrRowCount, "변수", j.MKV{"count": n}) } return 一.ID, nil @@ -121,7 +121,7 @@ func (一 エラー) Update( return 0, err } if n != 1 { - return 0, errors.Wrap(shift.ErrRowCount, "エラー", j.MKV{"count", n}) + return 0, errors.Wrap(shift.ErrRowCount, "エラー", j.MKV{"count": n}) } return 一.ID, nil diff --git a/shiftgen/testdata/case_specify_times/shift_gen.go.golden b/shiftgen/testdata/case_specify_times/shift_gen.go.golden index 667df99..77ffd7d 100644 --- a/shiftgen/testdata/case_specify_times/shift_gen.go.golden +++ b/shiftgen/testdata/case_specify_times/shift_gen.go.golden @@ -110,7 +110,7 @@ func (一 uFoo) Update( return 0, err } if n != 1 { - return 0, errors.Wrap(shift.ErrRowCount, "uFoo", j.MKV{"count", n}) + return 0, errors.Wrap(shift.ErrRowCount, "uFoo", j.MKV{"count": n}) } return 一.ID, nil diff --git a/shiftgen/testdata/case_version/shift_gen.go.golden b/shiftgen/testdata/case_version/shift_gen.go.golden index f3cd00c..207a4f0 100644 --- a/shiftgen/testdata/case_version/shift_gen.go.golden +++ b/shiftgen/testdata/case_version/shift_gen.go.golden @@ -72,7 +72,7 @@ func (一 update) Update( return 0, err } if n != 1 { - return 0, errors.Wrap(shift.ErrRowCount, "update", j.MKV{"count", n}) + return 0, errors.Wrap(shift.ErrRowCount, "update", j.MKV{"count": n}) } return 一.ID, nil