Merge pull request #6 from iochen/master
Support for more than one GOPATH
This commit is contained in:
commit
b9d40f01fb
21
main.go
21
main.go
@ -87,6 +87,19 @@ func parseEntry(line string) (Entry, error) {
|
||||
return Entry{}, errors.New("Invalid format: " + line)
|
||||
}
|
||||
|
||||
func DetectPath(path string) (string, error) {
|
||||
arrPath := strings.Split(path, string(filepath.ListSeparator))
|
||||
for _, content := range arrPath {
|
||||
fullPath := filepath.Join(content, "src", "github.com", "v2ray", "domain-list-community", "data")
|
||||
_, err := os.Stat(fullPath)
|
||||
if err == nil || os.IsExist(err) {
|
||||
return fullPath, nil
|
||||
}
|
||||
}
|
||||
err := errors.New("No file found in GOPATH")
|
||||
return "", err
|
||||
}
|
||||
|
||||
func Load(path string) (*List, error) {
|
||||
file, err := os.Open(path)
|
||||
if err != nil {
|
||||
@ -151,9 +164,13 @@ 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, err := DetectPath(os.Getenv("GOPATH"))
|
||||
if err != nil {
|
||||
fmt.Println("Failed: ", err)
|
||||
return
|
||||
}
|
||||
ref := make(map[string]*List)
|
||||
err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
|
||||
err = filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user