Skip to content

Commit a2dba13

Browse files
authored
refactor: remove reflects (#236)
1 parent 9f9ea2d commit a2dba13

File tree

5 files changed

+6
-18
lines changed

5 files changed

+6
-18
lines changed

internal/reflects/reflect.go

-8
This file was deleted.

kod.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import (
3030
"github.com/go-kod/kod/interceptor"
3131
"github.com/go-kod/kod/internal/hooks"
3232
"github.com/go-kod/kod/internal/kslog"
33-
"github.com/go-kod/kod/internal/reflects"
3433
"github.com/go-kod/kod/internal/registry"
3534
"github.com/go-kod/kod/internal/signals"
3635
)
@@ -254,7 +253,7 @@ func Run[T any, _ PointerToMain[T]](ctx context.Context, run func(context.Contex
254253
defer cancel()
255254

256255
// get the main component implementation
257-
main, err := kod.getImpl(ctx, reflects.TypeFor[T]())
256+
main, err := kod.getImpl(ctx, reflect.TypeFor[T]())
258257
if err != nil {
259258
return err
260259
}

registry.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111

1212
"github.com/go-kod/kod/internal/callgraph"
1313
"github.com/go-kod/kod/internal/hooks"
14-
"github.com/go-kod/kod/internal/reflects"
1514
"github.com/go-kod/kod/internal/registry"
1615
)
1716

@@ -226,7 +225,7 @@ func processRegistrations(regs []*Registration) (map[reflect.Type]bool, error) {
226225
for i := 0; i < reg.Impl.NumField(); i++ {
227226
f := reg.Impl.Field(i)
228227
switch {
229-
case f.Type.Implements(reflects.TypeFor[interface{ isRef() }]()):
228+
case f.Type.Implements(reflect.TypeFor[interface{ isRef() }]()):
230229
// f is a kod.Ref[T].
231230
v := f.Type.Field(0) // a Ref[T]'s value field
232231
// v是func 类型,取它的第一个返回值的类型
@@ -249,7 +248,7 @@ func processRegistrations(regs []*Registration) (map[reflect.Type]bool, error) {
249248
)
250249
errs = append(errs, err)
251250
}
252-
case f.Type.Implements(reflects.TypeFor[interface{ isLazyInit() }]()):
251+
case f.Type.Implements(reflect.TypeFor[interface{ isLazyInit() }]()):
253252
// f is a kod.LazyInit.
254253
lazyInitComponents[reg.Interface] = true
255254
}

registry_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88

99
"github.com/stretchr/testify/assert"
1010

11-
"github.com/go-kod/kod/internal/reflects"
1211
"github.com/go-kod/kod/internal/registry"
1312
)
1413

@@ -33,8 +32,8 @@ func TestValidateUnregisteredRef(t *testing.T) {
3332
regs := []*registry.Registration{
3433
{
3534
Name: "foo",
36-
Interface: reflects.TypeFor[foo](),
37-
Impl: reflects.TypeFor[fooImpl](),
35+
Interface: reflect.TypeFor[foo](),
36+
Impl: reflect.TypeFor[fooImpl](),
3837
},
3938
}
4039
_, err := processRegistrations(regs)

testing.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"github.com/samber/lo"
1010

1111
"github.com/go-kod/kod/internal/kslog"
12-
"github.com/go-kod/kod/internal/reflects"
1312
)
1413

1514
type ObservedLogs kslog.ObservedLogs
@@ -22,7 +21,7 @@ type fakeComponent struct {
2221
}
2322

2423
func Fake[T any](impl any) fakeComponent {
25-
t := reflects.TypeFor[T]()
24+
t := reflect.TypeFor[T]()
2625
if _, ok := impl.(T); !ok {
2726
panic(fmt.Sprintf("%T does not implement %v", impl, t))
2827
}

0 commit comments

Comments
 (0)