-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* improve ocm ref parsing * improve OCIRegistry Ref Mapping
- Loading branch information
1 parent
2a55b23
commit dce58d1
Showing
6 changed files
with
148 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and Open Component Model contributors. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package cpi | ||
|
||
import ( | ||
"sync" | ||
) | ||
|
||
type ParseHandler func(u *UniformRepositorySpec) error | ||
|
||
type registry struct { | ||
lock sync.RWMutex | ||
handlers map[string]ParseHandler | ||
} | ||
|
||
func (r *registry) Register(ty string, h ParseHandler) { | ||
r.lock.Lock() | ||
defer r.lock.Unlock() | ||
r.handlers[ty] = h | ||
} | ||
|
||
func (r *registry) Get(ty string) ParseHandler { | ||
r.lock.RLock() | ||
defer r.lock.RUnlock() | ||
return r.handlers[ty] | ||
} | ||
|
||
func (r *registry) Handle(u UniformRepositorySpec) (UniformRepositorySpec, error) { | ||
h := r.Get(u.Type) | ||
if h != nil { | ||
err := h(&u) | ||
return u, err | ||
} | ||
return u, nil | ||
} | ||
|
||
var parseregistry = ®istry{handlers: map[string]ParseHandler{}} | ||
|
||
func RegisterRefParseHandler(ty string, h ParseHandler) { | ||
parseregistry.Register(ty, h) | ||
} | ||
|
||
func GetRefParseHandler(ty string, h ParseHandler) { | ||
parseregistry.Get(ty) | ||
} | ||
|
||
func HandleRef(u UniformRepositorySpec) (UniformRepositorySpec, error) { | ||
return parseregistry.Handle(u) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters