Skip to content

Commit a5ea42b

Browse files
committed
Fix hyperbunTableForType for pointer types
1 parent 657f1e1 commit a5ea42b

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

hyperbun.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,10 @@ func annotate(err error, op string, kvs ...interface{}) error {
433433
func hyperbunTableForType[T any]() string {
434434
var t T
435435
typ := reflect.TypeOf(t)
436+
if typ.Kind() == reflect.Pointer {
437+
typ = typ.Elem()
438+
}
439+
436440
for i := 0; i < typ.NumField(); i++ {
437441
f := typ.Field(i)
438442
val, ok := f.Tag.Lookup("bun")

hyperbun_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ func TestHyperbunTableForType(t *testing.T) {
1818
assert.Equal(t, "test_struct", hyperbunTableForType[testStruct]())
1919
}
2020

21+
func TestHyperbunTableForPtrType(t *testing.T) {
22+
assert.Equal(t, "test_struct", hyperbunTableForType[*testStruct]())
23+
}
24+
2125
func TestAnnotateEven(t *testing.T) {
2226
assert.Equal(t,
2327
"performing TestAnnotate hello='world' id='0': test_error",

0 commit comments

Comments
 (0)