refact(target): Add NewFunc to registry

This adds a new requirement onto subtypes to register a NewFunc.
Previously the subtypes where implementing this function anyway, but the
target package was not including them in the registry. This resulted in
packages that use the target package needing to import the subtypes
directly, which we want to avoid.

This refactor will require the subtypes to register their NewFunc which
can then be used by `target.New` so packages that need to create targets
can do so by only using the target package.

This also updates the tcp subpackage to register a NewFunc.
This commit is contained in:
Timothy Messier committed 2021-12-03 10:19:29 -05:00
1 parent 1ae388438f
commit c9b99306e1
19 files changed
+279 -208

No files matched your search

+1 -1
View File
@@ -514,7 +514,7 @@ func (b *Server) CreateInitialTarget(ctx context.Context) (target.Target, error)
target.WithSessionConnectionLimit(int32(b.DevTargetSessionConnectionLimit)),
target.WithPublicId(b.DevTargetId),
}
t, err := tcp.New(b.DevProjectId, opts...)
t, err := target.New(ctx, tcp.Subtype, b.DevProjectId, opts...)
if err != nil {
return nil, fmt.Errorf("error creating in memory target: %w", err)
}