优化逻辑 提高速度

main
forget_the_bright 2 years ago
parent 24f34b061f
commit 1b5503369f

@ -17,9 +17,10 @@ import (
)
func fundVersion(version string) *config.UrlItem {
config.Url_Items = collector.ConvertCollectorToUrlItem(collector.GetOpenJDKArchiveReleasesInfo())
config.Url_Items = collector.ConvertCollectorToUrlItem(collector.GetOpenJDKArchiveReleasesInfo(), false)
for _, v := range config.Url_Items {
if v.SimpleName == version { //strings.Contains(v.SimpleName, version)
v.In.Sha256 = collector.GetSha256ByUrl(v.In.Sha256, true)
return v
}
}

@ -20,7 +20,7 @@ func remoteVersionLength(version string) string {
func listRemote(*cli.Context) (err error) {
use_version := inuse(goroot)
out := ansi.NewAnsiStdout()
rs := collector.ConvertCollectorToUrlItem(collector.GetOpenJDKArchiveReleasesInfo())
rs := collector.ConvertCollectorToUrlItem(collector.GetOpenJDKArchiveReleasesInfo(), false)
color.New(color.FgGreen).Fprintf(out, " %s\n", " version info")
for _, v := range rs {
if v.SimpleName == use_version { //strings.Contains(v.SimpleName, version)

@ -48,11 +48,15 @@ func getFileNameNoSuffix(file_name string) string {
return strings.ReplaceAll(file_name, "."+getFileTypeByFileName(file_name), "")
}
func getSha256ByUrl(url string) string {
func GetSha256ByUrl(url string, isGetSha256 bool) string {
if isGetSha256 {
resp, _ := http.Get(url)
defer resp.Body.Close()
bytes, _ := ioutil.ReadAll(resp.Body)
return string(bytes)
} else {
return url
}
}
func getFileTypeByFileName(filename string) string {

@ -10,7 +10,7 @@ import (
"github.com/forget-the-bright/j/internal/pkg/config"
)
func ConvertCollectorToUrlItem(colls []*Collector) []*config.UrlItem {
func ConvertCollectorToUrlItem(colls []*Collector, isGetSha256 bool) []*config.UrlItem {
var rs = make([]*config.UrlItem, 0)
for _, coll := range colls {
var item *Op_Item
@ -37,7 +37,7 @@ func ConvertCollectorToUrlItem(colls []*Collector) []*config.UrlItem {
In: &config.JavaFileItem{
FileName: item.FileName,
URL: item.Url,
Sha256: getSha256ByUrl(item.Sha256Url),
Sha256: GetSha256ByUrl(item.Sha256Url, isGetSha256),
},
SimpleName: coll.Version,
Expected: getFileNameNoSuffix(item.FileName),

Loading…
Cancel
Save