Skip to content

Commit

Permalink
map: Export MapSpec.checkCompatibility as MapSpec.Compatible
Browse files Browse the repository at this point in the history
Exporting MapSpec.checkCompatibility as MapSpec.Compatible

Suggested-by: Lorenz Bauer <i@lmb.io>
Suggested-by: Timo Beckers <timo@isovalent.com>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
  • Loading branch information
olsajiri authored and lmb committed Nov 23, 2022
1 parent 67abdec commit 79c7e55
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ func newCollectionLoader(coll *CollectionSpec, opts *CollectionOptions) (*collec
return nil, fmt.Errorf("replacement map %s not found in CollectionSpec", name)
}

if err := spec.checkCompatibility(m); err != nil {
if err := spec.Compatible(m); err != nil {
return nil, fmt.Errorf("using replacement map %s: %w", spec.Name, err)
}
}
Expand Down
8 changes: 6 additions & 2 deletions map.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,11 @@ type MapKV struct {
Value interface{}
}

func (ms *MapSpec) checkCompatibility(m *Map) error {
// Compatible returns nil if an existing map may be used instead of creating
// one from the spec.
//
// Returns an error wrapping [ErrMapIncompatible] otherwise.
func (ms *MapSpec) Compatible(m *Map) error {
switch {
case m.typ != ms.Type:
return fmt.Errorf("expected type %v, got %v: %w", ms.Type, m.typ, ErrMapIncompatible)
Expand Down Expand Up @@ -277,7 +281,7 @@ func newMapWithOptions(spec *MapSpec, opts MapOptions) (_ *Map, err error) {
}
defer closeOnError(m)

if err := spec.checkCompatibility(m); err != nil {
if err := spec.Compatible(m); err != nil {
return nil, fmt.Errorf("use pinned map %s: %w", spec.Name, err)
}

Expand Down

0 comments on commit 79c7e55

Please sign in to comment.