diff --git a/cli/install.go b/cli/install.go index 8da9208..4ff621c 100644 --- a/cli/install.go +++ b/cli/install.go @@ -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 } } diff --git a/cli/ls-remote.go b/cli/ls-remote.go index e3938ff..625321d 100644 --- a/cli/ls-remote.go +++ b/cli/ls-remote.go @@ -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) diff --git a/internal/pkg/collector/collector.go b/internal/pkg/collector/collector.go index f18d179..3435f9c 100644 --- a/internal/pkg/collector/collector.go +++ b/internal/pkg/collector/collector.go @@ -48,11 +48,15 @@ func getFileNameNoSuffix(file_name string) string { return strings.ReplaceAll(file_name, "."+getFileTypeByFileName(file_name), "") } -func getSha256ByUrl(url string) string { - resp, _ := http.Get(url) - defer resp.Body.Close() - bytes, _ := ioutil.ReadAll(resp.Body) - return string(bytes) +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 { diff --git a/internal/pkg/collector/openjdk_collector.go b/internal/pkg/collector/openjdk_collector.go index 05f5120..5372ec3 100644 --- a/internal/pkg/collector/openjdk_collector.go +++ b/internal/pkg/collector/openjdk_collector.go @@ -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),