diff options
| author | Jeff Carr <[email protected]> | 2024-11-27 21:41:57 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-11-27 21:41:57 -0600 |
| commit | 1321787a3b4c92ee9c9ac5c21a0c511c1c2eaff5 (patch) | |
| tree | 0ae8279368fae97b74935f7573f4f518ae67adbd /repos.helpers.go | |
| parent | ed3eacfe75e479e8c36cf7ba82a431c567f83602 (diff) | |
rename. always use plural form for proto files?
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'repos.helpers.go')
| -rw-r--r-- | repos.helpers.go | 46 |
1 files changed, 46 insertions, 0 deletions
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 +} |
