github.com/kayoticsully/syncthing@v0.8.9-0.20140724133906-c45a2fdc03f8/cmd/syncthing/upgrade_common.go (about) 1 package main 2 3 import ( 4 "bytes" 5 "strconv" 6 "strings" 7 ) 8 9 type githubRelease struct { 10 Tag string `json:"tag_name"` 11 Prerelease bool `json:"prerelease"` 12 Assets []githubAsset `json:"assets"` 13 } 14 15 type githubAsset struct { 16 URL string `json:"url"` 17 Name string `json:"name"` 18 } 19 20 func compareVersions(a, b string) int { 21 return bytes.Compare(versionParts(a), versionParts(b)) 22 } 23 24 func versionParts(v string) []byte { 25 parts := strings.Split(v, "-") 26 fields := strings.Split(parts[0], ".") 27 res := make([]byte, len(fields)) 28 for i, s := range fields { 29 v, _ := strconv.Atoi(s) 30 res[i] = byte(v) 31 } 32 return res 33 }