blob: 60cda4eb0b5a610df41b4d09c2b41af9f058b538 [file] [log] [blame]
Don Newton379ae252019-04-01 12:17:06 -04001// Copyright (C) MongoDB, Inc. 2017-present.
2//
3// Licensed under the Apache License, Version 2.0 (the "License"); you may
4// not use this file except in compliance with the License. You may obtain
5// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6
7package description
8
9import "strconv"
10
11// Version represents a software version.
12type Version struct {
13 Desc string
14 Parts []uint8
15}
16
17// AtLeast ensures that the version is at least as large as the "other" version.
18func (v Version) AtLeast(other ...uint8) bool {
19 for i := range other {
20 if i == len(v.Parts) {
21 return false
22 }
23 if v.Parts[i] < other[i] {
24 return false
25 }
26 }
27 return true
28}
29
30// String provides the string represtation of the Version.
31func (v Version) String() string {
32 if v.Desc == "" {
33 var s string
34 for i, p := range v.Parts {
35 if i != 0 {
36 s += "."
37 }
38 s += strconv.Itoa(int(p))
39 }
40 return s
41 }
42
43 return v.Desc
44}