func (t *components) Link(link map[string][]string) error {
if t.loadLink.CompareAndSwap(false, true) {
t.link = maps.Clone(link)
+ return nil
}
return ErrLinked
}
return Comp.Link(link)
}
-func PKG[T any](sign ...string) (pkg string) {
- pkg = reflect.TypeOf(*new(T)).PkgPath()
- for i := 0; i < len(sign); i++ {
- pkg += "." + sign[i]
+func Sign[T any](exsign ...string) (sign string) {
+ sign = reflect.TypeOf(*new(T)).PkgPath()
+ for i := 0; i < len(exsign); i++ {
+ sign += "." + exsign[i]
}
return
}
return errors.New("1.2.1")
})
- Comp.Link(map[string][]string{
+ if e := Comp.Link(map[string][]string{
`1`: {`1`},
- })
+ }); e != nil {
+ t.Fatal(e)
+ }
var s = 3
if e := Comp.Run(`1`, context.Background(), &s); e != nil {
func Test4(t *testing.T) {
type empty struct{}
- if pkg := PKG[empty](`1`, `2`); pkg != `github.com/qydysky/part/component.1.2` {
+ if pkg := Sign[empty](`1`, `2`); pkg != `empty github.com/qydysky/part/component.1.2` {
t.Fatal(pkg)
}
}
--- /dev/null
+package testdata
+
+import (
+ eg "github.com/qydysky/part/component/testdata/eg"
+
+ comp "github.com/qydysky/part/component"
+)
+
+func init() {
+ var linkMap = map[string][]string{
+ `test`: {
+ comp.Sign[eg.Sign](),
+ },
+ }
+ comp.Link(linkMap)
+}
--- /dev/null
+package testdata
+
+import (
+ "context"
+ "testing"
+
+ comp "github.com/qydysky/part/component"
+)
+
+func TestMain(t *testing.T) {
+ var s = "s"
+ if e := comp.Run[string](`test`, context.Background(), &s); e != nil {
+ t.Fatal(e)
+ }
+}
--- /dev/null
+package eg
+
+import (
+ "context"
+
+ comp "github.com/qydysky/part/component"
+)
+
+type Sign struct{}
+
+func init() {
+ if e := comp.Put[string](comp.Sign[Sign](), deal); e != nil {
+ panic(e)
+ }
+}
+
+func deal(ctx context.Context, ptr *string) error {
+ println(*ptr)
+ return nil
+}