gitpb/repo.helpers.go

47 lines
853 B
Go
Raw Normal View History

package gitpb
2024-11-27 14:52:12 -06:00
// delete a gopath:
// myrepos.DeleteByPath("go.wit.com/apps/go-clone")
func (all *Repos) DeleteByPath(gopath string) *Repo {
repolock.Lock()
defer repolock.Unlock()
for i, _ := range all.Repos {
if all.Repos[i].GoPath == gopath {
all.Repos[i] = all.Repos[len(all.Repos)-1]
all.Repos = all.Repos[:len(all.Repos)-1]
return nil
}
}
return nil
}
2024-11-27 14:52:12 -06:00
// find a package by gopath
2024-11-27 14:55:39 -06:00
func (all *Repos) FindByGoPath(gopath string) *Repo {
2024-11-27 14:52:12 -06:00
repolock.RLock()
defer repolock.RUnlock()
for _, p := range all.Repos {
if p.GoPath == gopath {
return p
}
}
return nil
}
// enforces no duplicate gopath's
func (all *Repos) add(newP *Repo) bool {
repolock.Lock()
defer repolock.Unlock()
for _, p := range all.Repos {
if p.GoPath == newP.GoPath {
return false
}
}
all.Repos = append(all.Repos, newP)
return true
}