MCPcopy
hub / github.com/tinode/chat / parseVersion

Function parseVersion

server/utils.go:308–327  ·  view source on GitHub ↗

Parses semantic version string in the following formats: 1.2, 1.2abc, 1.2.3, 1.2.3-abc, v0.12.34-rc5 Unparceable values are replaced with zeros.

(vers string)

Source from the content-addressed store, hash-verified

306//
307// Unparceable values are replaced with zeros.
308func parseVersion(vers string) int {
309 var major, minor, patch int
310 // Maybe remove the optional "v" prefix.
311 vers = strings.TrimPrefix(vers, "v")
312
313 // We can handle 3 parts only.
314 parts := strings.SplitN(vers, ".", 3)
315 count := len(parts)
316 if count > 0 {
317 major = parseVersionPart(parts[0])
318 if count > 1 {
319 minor = parseVersionPart(parts[1])
320 if count > 2 {
321 patch = parseVersionPart(parts[2])
322 }
323 }
324 }
325
326 return (major << 16) | (minor << 8) | patch
327}
328
329// Version as a base-10 number. Used by monitoring.
330func base10Version(hex int) int64 {

Callers 4

TestParseVersionFunction · 0.85
session.goFile · 0.85
helloMethod · 0.85
mainFunction · 0.85

Calls 1

parseVersionPartFunction · 0.85

Tested by 1

TestParseVersionFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…