mirror of
https://github.com/safing/portbase
synced 2025-09-01 18:19:57 +00:00
Add clean export function for updater.Resource
This commit is contained in:
parent
38d3c839ef
commit
8421b8fba8
2 changed files with 22 additions and 3 deletions
|
@ -1,7 +1,6 @@
|
||||||
package updater
|
package updater
|
||||||
|
|
||||||
// Export exports the list of resources. All resources must be
|
// Export exports the list of resources.
|
||||||
// locked when accessed.
|
|
||||||
func (reg *ResourceRegistry) Export() map[string]*Resource {
|
func (reg *ResourceRegistry) Export() map[string]*Resource {
|
||||||
reg.RLock()
|
reg.RLock()
|
||||||
defer reg.RUnlock()
|
defer reg.RUnlock()
|
||||||
|
@ -9,7 +8,7 @@ func (reg *ResourceRegistry) Export() map[string]*Resource {
|
||||||
// copy the map
|
// copy the map
|
||||||
copiedResources := make(map[string]*Resource)
|
copiedResources := make(map[string]*Resource)
|
||||||
for key, val := range reg.resources {
|
for key, val := range reg.resources {
|
||||||
copiedResources[key] = val
|
copiedResources[key] = val.Export()
|
||||||
}
|
}
|
||||||
|
|
||||||
return copiedResources
|
return copiedResources
|
||||||
|
|
|
@ -117,6 +117,26 @@ func (rv *ResourceVersion) isBetaVersionNumber() bool { //nolint:unused
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Export makes a copy of the resource with only the exposed information.
|
||||||
|
func (res *Resource) Export() *Resource {
|
||||||
|
res.Lock()
|
||||||
|
defer res.Unlock()
|
||||||
|
|
||||||
|
// Copy attibutes.
|
||||||
|
export := &Resource{
|
||||||
|
Identifier: res.Identifier,
|
||||||
|
Versions: make([]*ResourceVersion, len(res.Versions)),
|
||||||
|
ActiveVersion: res.ActiveVersion,
|
||||||
|
SelectedVersion: res.SelectedVersion,
|
||||||
|
}
|
||||||
|
// Copy Versions slice.
|
||||||
|
for i := 0; i < len(res.Versions); i++ {
|
||||||
|
export.Versions[i] = res.Versions[i]
|
||||||
|
}
|
||||||
|
|
||||||
|
return export
|
||||||
|
}
|
||||||
|
|
||||||
// Len is the number of elements in the collection.
|
// Len is the number of elements in the collection.
|
||||||
// It implements sort.Interface for ResourceVersion.
|
// It implements sort.Interface for ResourceVersion.
|
||||||
func (res *Resource) Len() int {
|
func (res *Resource) Len() int {
|
||||||
|
|
Loading…
Add table
Reference in a new issue