now using the awesome golang 1.24 'iter'

This commit is contained in:
Jeff Carr 2025-03-19 06:40:36 -05:00
parent b587843836
commit f87da2b041
1 changed files with 4 additions and 12 deletions

16
wit.go
View File

@ -7,9 +7,7 @@ import (
)
func (m *Machine) IsInstalled(name string) bool {
loop := m.Packages.SortByName()
for loop.Scan() {
p := loop.Next()
for p := range m.Packages.IterByName() {
if name == p.Name {
// log.Info("package installed:", p.Name, p.Version, p.PkgName)
return true
@ -21,9 +19,7 @@ func (m *Machine) IsInstalled(name string) bool {
}
func (m *Machine) FindInstalledByName(name string) *Package {
loop := m.Packages.SortByName()
for loop.Scan() {
p := loop.Next()
for p := range m.Packages.IterByName() {
if name == p.Name {
// log.Info("package installed:", p.Name, p.Version, p.PkgName)
return p
@ -38,9 +34,7 @@ func (m *Machine) FindInstalledByName(name string) *Package {
// if version == "", return the first name found
func (m *Machine) FindVersion(name string, version string) *Package {
// first check all installed versions
loop := m.Packages.SortByName()
for loop.Scan() {
p := loop.Next()
for p := range m.Packages.IterByName() {
if name == p.Name {
if version == "" {
return p
@ -53,9 +47,7 @@ func (m *Machine) FindVersion(name string, version string) *Package {
}
// check all wit packages
loop = m.Wit.SortByName()
for loop.Scan() {
p := loop.Next()
for p := range m.Wit.IterByName() {
if name == p.Name {
if version == "" {
return p