String returns the full version string included pre-release and metadata information. This value is rebuilt according to the parsed segments and other information. Therefore, ambiguities in the version string such as prefixed zeroes (1.04.0 => 1.4.0), `v` prefix (v1.0.0 => 1.0.0), and missing parts
()
| 365 | // missing parts (1.0 => 1.0.0) will be made into a canonicalized form |
| 366 | // as shown in the parenthesized examples. |
| 367 | func (v *Version) String() string { |
| 368 | var buf bytes.Buffer |
| 369 | fmtParts := make([]string, len(v.segments)) |
| 370 | for i, s := range v.segments { |
| 371 | // We can ignore err here since we've pre-parsed the values in segments |
| 372 | str := strconv.FormatInt(s, 10) |
| 373 | fmtParts[i] = str |
| 374 | } |
| 375 | _, _ = fmt.Fprintf(&buf, "%s", strings.Join(fmtParts, ".")) |
| 376 | if v.pre != "" { |
| 377 | _, _ = fmt.Fprintf(&buf, "-%s", v.pre) |
| 378 | } |
| 379 | if v.metadata != "" { |
| 380 | _, _ = fmt.Fprintf(&buf, "+%s", v.metadata) |
| 381 | } |
| 382 | |
| 383 | return buf.String() |
| 384 | } |
| 385 | |
| 386 | // Original returns the original parsed version as-is, including any |
| 387 | // potential whitespace, `v` prefix, etc. |