From 6b725b0a3b1704789ea7243a4ab55ce1cee1f43c Mon Sep 17 00:00:00 2001 From: qydysky Date: Sun, 13 Aug 2023 01:53:43 +0800 Subject: [PATCH] add --- component/Component.go | 10 ++++++++++ component/Component_test.go | 9 +++++++++ 2 files changed, 19 insertions(+) diff --git a/component/Component.go b/component/Component.go index a315c5f..f61c9d2 100644 --- a/component/Component.go +++ b/component/Component.go @@ -4,6 +4,7 @@ import ( "context" "errors" "maps" + "reflect" "sync/atomic" psync "github.com/qydysky/part/sync" @@ -81,4 +82,13 @@ func Link(link map[string][]string) error { return Comp.Link(link) } +func PKG(sign ...string) (pkg string) { + type empty struct{} + pkg = reflect.TypeOf(empty{}).PkgPath() + for i := 0; i < len(sign); i++ { + pkg += "." + sign[i] + } + return +} + var Comp *components = NewComp() diff --git a/component/Component_test.go b/component/Component_test.go index 2592558..036d827 100644 --- a/component/Component_test.go +++ b/component/Component_test.go @@ -9,6 +9,7 @@ import ( ) func Test1(t *testing.T) { + Comp = NewComp() Put(`1`, func(ctx context.Context, ptr *int) error { if *ptr > 1 { return nil @@ -60,6 +61,7 @@ func Test1(t *testing.T) { } func TestDot(t *testing.T) { + Comp = NewComp() Put[int](`1`, func(ctx context.Context, ptr *int) error { if *ptr == 1 { return nil @@ -83,6 +85,7 @@ func TestDot(t *testing.T) { } func Test3(t *testing.T) { + Comp = NewComp() sumup := func(ctx context.Context, ptr *int) error { return nil } @@ -100,6 +103,12 @@ func Test3(t *testing.T) { } } +func Test4(t *testing.T) { + if pkg := PKG(`1`, `2`); pkg != `github.com/qydysky/part/component.1.2` { + t.Fatal(pkg) + } +} + func Benchmark2(b *testing.B) { for i := 0; i < b.N; i++ { Put[int](strconv.Itoa(i), func(ctx context.Context, ptr *int) error { -- 2.39.2