-
Notifications
You must be signed in to change notification settings - Fork 0
/
proxy.go
51 lines (42 loc) · 804 Bytes
/
proxy.go
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
47
48
49
50
51
package vcs
import (
"strings"
"github.com/4396/pkg/vcs/parser"
"github.com/4396/pkg/vcs/repository"
)
type pkg struct {
Repo string
Base string
}
var (
pkgs = make(map[string]pkg)
)
func Proxy(name, repo, base string) {
pkgs[name] = pkg{repo, base}
}
func proxyParse(path string) (string, string, error) {
return githubParse(path)
}
func proxyRepository(pkg string) (repo, base string, err error) {
for k, v := range pkgs {
if strings.HasPrefix(pkg, k) {
repo = v.Repo
base = v.Base
return
}
}
err = ErrInvalidPackage
return
}
func init() {
match := func(s string) bool {
for k := range pkgs {
if strings.HasPrefix(s, k) {
return true
}
}
return false
}
parser.Registerf(match, proxyParse, true)
repository.Registerf(match, proxyRepository, true)
}