Don Newton | 379ae25 | 2019-04-01 12:17:06 -0400 | [diff] [blame^] | 1 | // 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 | |
| 7 | package description |
| 8 | |
| 9 | import "strconv" |
| 10 | |
| 11 | // Version represents a software version. |
| 12 | type 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. |
| 18 | func (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. |
| 31 | func (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 | } |