github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/release/version/version.go (about) 1 // Copyright 2015 Keybase, Inc. All rights reserved. Use of 2 // this source code is governed by the included BSD license. 3 4 package version 5 6 import ( 7 "fmt" 8 "regexp" 9 "time" 10 ) 11 12 // Parse parses version, time and commit info from string 13 func Parse(name string) (version string, versionShort string, t time.Time, commit string, err error) { 14 versionRegex := regexp.MustCompile(`(\d+\.\d+\.\d+)[-.](\d+)[+.]([[:alnum:]]+)`) 15 parts := versionRegex.FindAllStringSubmatch(name, -1) 16 if len(parts) == 0 || len(parts[0]) < 4 { 17 err = fmt.Errorf("Unable to parse: %s", name) 18 return 19 } 20 versionShort = parts[0][1] 21 date := parts[0][2] 22 commit = parts[0][3] 23 version = fmt.Sprintf("%s-%s+%s", versionShort, date, commit) 24 t, _ = time.Parse("20060102150405", date) 25 return 26 }