From 9f9234c49794f0c1afa1f6222e4cafc23f920734 Mon Sep 17 00:00:00 2001 From: qydysky Date: Sun, 13 Aug 2023 02:52:28 +0800 Subject: [PATCH] add --- component/Component.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/component/Component.go b/component/Component.go index f61c9d2..4e95f63 100644 --- a/component/Component.go +++ b/component/Component.go @@ -31,7 +31,7 @@ func NewComp() *components { func (t *components) Put(Key string, Deal func(ctx context.Context, ptr any) error) error { _, loaded := t.m.LoadOrStore(Key, Deal) if loaded { - return ErrConflict + return errors.Join(ErrConflict, errors.New(Key)) } return nil } @@ -46,7 +46,7 @@ func (t *components) Run(key string, ctx context.Context, ptr any) error { } links := t.link[key] if len(links) == 0 { - return ErrNoLink + return ErrNoExist } for i := 0; i < len(links); i++ { if deal, ok := t.m.LoadV(links[i]).(func(ctx context.Context, ptr any) error); ok { @@ -82,9 +82,8 @@ 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() +func PKG(t any, sign ...string) (pkg string) { + pkg = reflect.TypeOf(t).PkgPath() for i := 0; i < len(sign); i++ { pkg += "." + sign[i] } -- 2.39.2