diff --git a/hyperbun.go b/hyperbun.go index 25aabeb..f864aa9 100644 --- a/hyperbun.go +++ b/hyperbun.go @@ -433,6 +433,10 @@ func annotate(err error, op string, kvs ...interface{}) error { func hyperbunTableForType[T any]() string { var t T typ := reflect.TypeOf(t) + if typ.Kind() == reflect.Pointer { + typ = typ.Elem() + } + for i := 0; i < typ.NumField(); i++ { f := typ.Field(i) val, ok := f.Tag.Lookup("bun") diff --git a/hyperbun_test.go b/hyperbun_test.go index 68c9a8f..d6ce926 100644 --- a/hyperbun_test.go +++ b/hyperbun_test.go @@ -18,6 +18,10 @@ func TestHyperbunTableForType(t *testing.T) { assert.Equal(t, "test_struct", hyperbunTableForType[testStruct]()) } +func TestHyperbunTableForPtrType(t *testing.T) { + assert.Equal(t, "test_struct", hyperbunTableForType[*testStruct]()) +} + func TestAnnotateEven(t *testing.T) { assert.Equal(t, "performing TestAnnotate hello='world' id='0': test_error",