support for more than one GOPATH

This commit is contained in:
Richard Chen 2018-08-23 09:05:17 +08:00
parent 5877deb8ea
commit 394aa8f937
No known key found for this signature in database
GPG Key ID: C789FC6FC2E7BD21

21
main.go
View File

@ -87,6 +87,25 @@ func parseEntry(line string) (Entry, error) {
return Entry{}, errors.New("Invalid format: " + line)
}
func split(r rune) bool {
if r == ':' {
return true
}
return false
}
func DetectionPath(gopath string) string {
path := os.Getenv(gopath)
arrPath := strings.FieldsFunc(path,split)
for _,content := range arrPath {
fullPath := filepath.Join(content, "src", "github.com", "v2ray", "domain-list-community", "data")
_, err1 := os.Stat(fullPath+"/")
if err1 == nil || os.IsExist(err1) {
return fullPath
}
}
panic("No File found in GOPATH")
}
func Load(path string) (*List, error) {
file, err := os.Open(path)
if err != nil {
@ -151,7 +170,7 @@ func ParseList(list *List, ref map[string]*List) (*ParsedList, error) {
}
func main() {
dir := filepath.Join(os.Getenv("GOPATH"), "src", "github.com", "v2ray", "domain-list-community", "data")
dir := DetectionPath("GOPATH")
ref := make(map[string]*List)
err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
if err != nil {