From 1321787a3b4c92ee9c9ac5c21a0c511c1c2eaff5 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Wed, 27 Nov 2024 21:41:57 -0600 Subject: rename. always use plural form for proto files? Signed-off-by: Jeff Carr --- repos.helpers.go | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 repos.helpers.go (limited to 'repos.helpers.go') diff --git a/repos.helpers.go b/repos.helpers.go new file mode 100644 index 0000000..3420526 --- /dev/null +++ b/repos.helpers.go @@ -0,0 +1,46 @@ +package gitpb + +// 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 +} + +// find a package by gopath +func (all *Repos) FindByGoPath(gopath string) *Repo { + 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 +} -- cgit v1.2.3