优化逻辑 提高速度
This commit is contained in:
parent
24f34b061f
commit
1b5503369f
@ -17,9 +17,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func fundVersion(version string) *config.UrlItem {
|
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 {
|
for _, v := range config.Url_Items {
|
||||||
if v.SimpleName == version { //strings.Contains(v.SimpleName, version)
|
if v.SimpleName == version { //strings.Contains(v.SimpleName, version)
|
||||||
|
v.In.Sha256 = collector.GetSha256ByUrl(v.In.Sha256, true)
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func remoteVersionLength(version string) string {
|
|||||||
func listRemote(*cli.Context) (err error) {
|
func listRemote(*cli.Context) (err error) {
|
||||||
use_version := inuse(goroot)
|
use_version := inuse(goroot)
|
||||||
out := ansi.NewAnsiStdout()
|
out := ansi.NewAnsiStdout()
|
||||||
rs := collector.ConvertCollectorToUrlItem(collector.GetOpenJDKArchiveReleasesInfo())
|
rs := collector.ConvertCollectorToUrlItem(collector.GetOpenJDKArchiveReleasesInfo(), false)
|
||||||
color.New(color.FgGreen).Fprintf(out, " %s\n", " version info")
|
color.New(color.FgGreen).Fprintf(out, " %s\n", " version info")
|
||||||
for _, v := range rs {
|
for _, v := range rs {
|
||||||
if v.SimpleName == use_version { //strings.Contains(v.SimpleName, version)
|
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), "")
|
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)
|
resp, _ := http.Get(url)
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
bytes, _ := ioutil.ReadAll(resp.Body)
|
bytes, _ := ioutil.ReadAll(resp.Body)
|
||||||
return string(bytes)
|
return string(bytes)
|
||||||
|
} else {
|
||||||
|
return url
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getFileTypeByFileName(filename string) string {
|
func getFileTypeByFileName(filename string) string {
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
"github.com/forget-the-bright/j/internal/pkg/config"
|
"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)
|
var rs = make([]*config.UrlItem, 0)
|
||||||
for _, coll := range colls {
|
for _, coll := range colls {
|
||||||
var item *Op_Item
|
var item *Op_Item
|
||||||
@ -37,7 +37,7 @@ func ConvertCollectorToUrlItem(colls []*Collector) []*config.UrlItem {
|
|||||||
In: &config.JavaFileItem{
|
In: &config.JavaFileItem{
|
||||||
FileName: item.FileName,
|
FileName: item.FileName,
|
||||||
URL: item.Url,
|
URL: item.Url,
|
||||||
Sha256: getSha256ByUrl(item.Sha256Url),
|
Sha256: GetSha256ByUrl(item.Sha256Url, isGetSha256),
|
||||||
},
|
},
|
||||||
SimpleName: coll.Version,
|
SimpleName: coll.Version,
|
||||||
Expected: getFileNameNoSuffix(item.FileName),
|
Expected: getFileNameNoSuffix(item.FileName),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user