-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcollector.go
42 lines (36 loc) · 1.11 KB
/
collector.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
package collector
import (
"strings"
"github.com/voidint/g/collector/aliyun"
"github.com/voidint/g/collector/official"
"github.com/voidint/g/version"
)
// Collector 版本信息采集器
type Collector interface {
// 返回稳定版本列表
StableVersions() (items []*version.Version, err error)
// 返回非稳定版本列表
UnstableVersions() (items []*version.Version, err error)
// 返回已归档版本列表
ArchivedVersions() (items []*version.Version, err error)
// 返回所有版本列表
AllVersions() (items []*version.Version, err error)
}
// NewCollector 返回首个可用的采集器实例
func NewCollector(urls ...string) (c Collector, err error) {
if len(urls) == 0 {
urls = []string{official.DefaultDownloadPageURL}
}
for i := range urls {
urls[i] = strings.TrimSpace(urls[i])
if urls[i] != "" && (strings.HasPrefix(aliyun.DownloadPageURL, urls[i]) || strings.HasPrefix(urls[i], aliyun.DownloadPageURL)) {
if c, err = aliyun.NewCollector(); err == nil {
return c, nil
}
}
if c, err = official.NewCollector(urls[i]); err == nil {
return c, nil
}
}
return c, err
}