blob: 50f3277eb382af0649655892aa858262a9532497 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
package gitpb
// delete a gopath:
// myrepos.DeleteByPath("go.wit.com/apps/go-clone")
func (all *Repos) DeleteByPath(gopath string) *Repo {
reposMu.Lock()
defer reposMu.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 {
reposMu.RLock()
defer reposMu.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 {
reposMu.Lock()
defer reposMu.Unlock()
for _, p := range all.Repos {
if p.GoPath == newP.GoPath {
return false
}
}
all.Repos = append(all.Repos, newP)
return true
}
|