From c9d99d669347dd11ea12ced051f049fc6cfbfab0 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Wed, 27 Nov 2024 14:52:12 -0600 Subject: more code cleanups --- repo.helpers.go | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) (limited to 'repo.helpers.go') diff --git a/repo.helpers.go b/repo.helpers.go index f23393c..7cc6d5a 100644 --- a/repo.helpers.go +++ b/repo.helpers.go @@ -1,8 +1,7 @@ package gitpb -// this is becoming a standard format -// todo: autogenerate this from the .proto file? - +// delete a gopath: +// myrepos.DeleteByPath("go.wit.com/apps/go-clone") func (all *Repos) DeleteByPath(gopath string) *Repo { repolock.Lock() defer repolock.Unlock() @@ -16,3 +15,32 @@ func (all *Repos) DeleteByPath(gopath string) *Repo { } return nil } + +// find a package by gopath +func (all *Repos) FindByPath(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