-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor of the code base: Remove underscore functions and refactor a panic #59
Changes from 3 commits
bcbadfc
e057b69
f92e07b
7871e47
3b93b44
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,4 +19,3 @@ import ( | |
) | ||
|
||
var TestData = env.TestData | ||
var FileSystem = env.FileSystem |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,10 +54,6 @@ func NewConfigTypeScheme(defaultRepoDecoder runtime.TypedObjectDecoder) ConfigTy | |
return &configTypeScheme{scheme} | ||
} | ||
|
||
func (t *configTypeScheme) AddKnowntypes(s ConfigTypeScheme) { | ||
t.Scheme.AddKnownTypes(s) | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why have you removed this. It is a useful interface function, even if it is not yet used. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not following. This function is a lowerCase AddKnownTypes for some reason. It was never called from anything. Not even using reflection I did a search for the string. :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are right. It is intended for a library user who does not want do deal with errors. Because of its parameter type, calling the base method cannot cause an error. It assures the correct element type. And the only error reason cannot appear, so the errors code can be ignored. Because Go does not support method overloading by parameter types, I had to choose another method type. May be with Generics this will be better, but so far the lib is without generic, and I still would prefer to keep it this way. Basically I already tried some more complicated cases, but the Go generics solution failed to handle them correctly. There are two important things missing: upper AND lower bound operator, and a much better type inference. |
||
func (t *configTypeScheme) GetConfigType(name string) ConfigType { | ||
d := t.GetDecoder(name) | ||
if d == nil { | ||
|
@@ -68,16 +64,21 @@ func (t *configTypeScheme) GetConfigType(name string) ConfigType { | |
|
||
func (t *configTypeScheme) RegisterByDecoder(name string, decoder runtime.TypedObjectDecoder) error { | ||
if _, ok := decoder.(ConfigType); !ok { | ||
errors.ErrInvalid("type", reflect.TypeOf(decoder).String()) | ||
return errors.ErrInvalid("type", reflect.TypeOf(decoder).String()) | ||
} | ||
return t.Scheme.RegisterByDecoder(name, decoder) | ||
} | ||
|
||
func (t *configTypeScheme) AddKnownTypes(scheme runtime.Scheme) { | ||
func (t *configTypeScheme) AddKnownTypes(scheme runtime.Scheme) error { | ||
if _, ok := scheme.(ConfigTypeScheme); !ok { | ||
panic("can only add RepositoryTypeSchemes") | ||
return errors.ErrInvalid("type", reflect.TypeOf(scheme).String(), "expected", "ConfigTypeScheme") | ||
} | ||
t.Scheme.AddKnownTypes(scheme) | ||
|
||
if err := t.Scheme.AddKnownTypes(scheme); err != nil { | ||
return fmt.Errorf("failed to add known type in config type scheme: %w", err) | ||
} | ||
|
||
return nil | ||
mandelsoft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
func (t *configTypeScheme) Register(name string, rtype ConfigType) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,13 +21,11 @@ import ( | |
"github.com/mandelsoft/vfs/pkg/readonlyfs" | ||
"github.com/mandelsoft/vfs/pkg/vfs" | ||
|
||
"github.com/open-component-model/ocm/pkg/contexts/datacontext/attrs/vfsattr" | ||
|
||
"github.com/open-component-model/ocm/pkg/common/accessio" | ||
"github.com/open-component-model/ocm/pkg/contexts/config" | ||
"github.com/open-component-model/ocm/pkg/contexts/credentials" | ||
"github.com/open-component-model/ocm/pkg/contexts/datacontext/attrs/vfsattr" | ||
"github.com/open-component-model/ocm/pkg/contexts/oci" | ||
|
||
"github.com/open-component-model/ocm/pkg/contexts/ocm" | ||
) | ||
|
||
|
@@ -45,25 +43,6 @@ func (dummyOption) Mount(*composefs.ComposedFileSystem) error { | |
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
type fsOpt struct { | ||
dummyOption | ||
path string | ||
fs vfs.FileSystem | ||
} | ||
|
||
func FileSystem(fs vfs.FileSystem, path string) fsOpt { | ||
return fsOpt{ | ||
path: path, | ||
fs: fs, | ||
} | ||
} | ||
|
||
func (o fsOpt) Mount(cfs *composefs.ComposedFileSystem) error { | ||
return cfs.Mount(o.path, o.fs) | ||
} | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a valid interface function of the lib. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure. Completely unused by anything. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's why I removed it. It clutters the code base. Unless there is some reference somewhere to this? It is in version control, so once we DO need for something, we can always just add it back in. :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is intended as a library, Therefore is natural, that not all methods/functions are already used. The included CLI code is just one client of the lib, but not necessarily the only one. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, if it is intended to be used as a library, this should be made clear that this is an open option. Either through documentation or through other means, such as usage or packaging that surfaces this. But that's a different problem. I can put this back in. :) |
||
type tdOpt struct { | ||
dummyOption | ||
path string | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you urgently want to change this, it should be changed everywhere. There are several commands following this pattern.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I change these as I encounter them. This PR is not concerned with that. However, I can open a separate PR just with naming refactors. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that seems to be better. I tried to keep the codebase somehow consistent. So if we change these method names (no problem with that :-) ). we should change it in all commands, because these methods have the same meaning and name in all those commands.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, will do that ( open a separate PR ).