Exemple #1
0
func getTotalImportList(path string) ([]string, error) {
	importList, err := getImportList(path, nil)
	if err != nil {
		return nil, err
	}
	pathHash := make(map[string]bool)
	for len(importList) > 0 {
		subList := make([]string, 0)
		for _, v := range importList {
			list, err := getImportList(v, pathHash)
			if err != nil {
				return nil, err
			}
			if len(list) > 0 {
				subList = append(subList, list...)
			}
		}
		importList = subList
	}
	totalImportList := make([]string, 0)
	for key, _ := range pathHash {
		totalImportList = append(totalImportList, key)
	}
	convert.String(123)
	return totalImportList, nil
}
Exemple #2
0
func main() {
	list, err := getTotalImportList("./")
	if err != nil {
		panic(err)
	}

	excel := xlsx.NewFile()
	sheetLicense, _ := excel.AddSheet("License")
	sheetNotFound, _ := excel.AddSheet("Not Found")
	goPath := os.Getenv("GOPATH")
	for _, v := range list {
		src := v[len(goPath)+5:]
		url := fmt.Sprintf("https://libraries.io/go/%s", strings.Replace(src, `\`, "%2F", -1))
		doc, err := goquery.NewDocument(url)
		if err != nil {
			println(err)
			continue
		}

		src = strings.Replace(src, `\`, `/`, -1)
		license := strings.TrimSpace(doc.Find(".col-md-8").Eq(1).Find("p").Eq(4).Text())
		idx := strings.Index(license, "License: ")
		if idx >= 0 {
			r := sheetLicense.AddRow()
			r.AddCell().SetString(src)
			r.AddCell().SetString(license[idx+9:])
		} else {
			r := sheetNotFound.AddRow()
			r.AddCell().SetString(src)
		}
	}
	excel.Save(fmt.Sprintf("./License_%s.xlsx", strings.Replace(strings.Replace(strings.Replace(convert.String(time.Now())[:19], ":", "", -1), "-", "", -1), " ", "", -1)))
}