loader revisited
This commit is contained in:
+1
-46
@@ -1,59 +1,14 @@
|
||||
package loader
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"fmt"
|
||||
"galaxy/connector"
|
||||
"galaxy/util"
|
||||
"runtime"
|
||||
"slices"
|
||||
)
|
||||
|
||||
func resolvePluginFile(version string) string {
|
||||
return libUIPluginFile + "-" + version
|
||||
}
|
||||
|
||||
// latestVersion should return VersionInfo with the latest Version for the current OS
|
||||
func latestVersion(versions []connector.VersionInfo) (connector.VersionInfo, bool, error) {
|
||||
os := runtime.GOOS
|
||||
versions = slices.DeleteFunc(versions, func(v connector.VersionInfo) bool { return v.OS != os })
|
||||
if len(versions) == 0 {
|
||||
return connector.VersionInfo{}, false, nil
|
||||
}
|
||||
type v struct {
|
||||
vi *connector.VersionInfo
|
||||
sv *util.SemVer
|
||||
}
|
||||
semvers := make([]*v, len(versions))
|
||||
for i := range versions {
|
||||
sv, err := util.ParseSemver(versions[i].Version)
|
||||
if err != nil {
|
||||
return connector.VersionInfo{}, false, fmt.Errorf("latest version: %w", err)
|
||||
}
|
||||
semvers[i] = &v{
|
||||
vi: &versions[i],
|
||||
sv: &sv,
|
||||
}
|
||||
}
|
||||
slices.SortFunc(semvers, func(a, b *v) int { return util.CompareSemver(*b.sv, *a.sv) })
|
||||
return *semvers[0].vi, true, nil
|
||||
}
|
||||
import "crypto/sha256"
|
||||
|
||||
// SumSHA256 calculates SHA-256 for the provided byte slice and returns
|
||||
// the raw 32-byte digest as a fixed-size array.
|
||||
//
|
||||
// The function does not modify the input data.
|
||||
// The returned value is the binary digest, not a hex string.
|
||||
// Use digest[:] if a []byte is needed.
|
||||
func SumSHA256(data []byte) [32]byte {
|
||||
return sha256.Sum256(data)
|
||||
}
|
||||
|
||||
// EqualSHA256 returns true when both SHA-256 digests are identical.
|
||||
//
|
||||
// Since SHA-256 digest is represented as a fixed-size array [32]byte,
|
||||
// Go allows direct value comparison with ==.
|
||||
// This is the simplest and fastest approach for ordinary equality checks.
|
||||
func EqualSHA256(a, b [32]byte) bool {
|
||||
return a == b
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user