...
1 package version
2
3 import (
4 "fmt"
5 "strconv"
6 "strings"
7 )
8
9
10
11 type channelVersion struct {
12 channel string
13 version string
14 hotpatch *int64
15 original string
16 }
17
18
19
20 const hotpatchSuffix = "Hotpatch"
21
22 func (cv channelVersion) String() string {
23 return cv.original
24 }
25
26
27
28
29
30 func (cv channelVersion) updateChannel() string {
31 if cv.hotpatch != nil {
32 return cv.channel + hotpatchSuffix
33 }
34 return cv.channel
35 }
36
37
38
39 func (cv channelVersion) versionWithHotpatch() string {
40 if cv.hotpatch == nil {
41 return cv.version
42 }
43 return fmt.Sprintf("%s-%d", cv.version, *cv.hotpatch)
44 }
45
46 func (cv channelVersion) hotpatchEqual(other channelVersion) bool {
47 if cv.hotpatch == nil && other.hotpatch == nil {
48 return true
49 }
50 if cv.hotpatch == nil || other.hotpatch == nil {
51 return false
52 }
53 return *cv.hotpatch == *other.hotpatch
54 }
55
56
57
58
59
60
61
62 func parseChannelVersion(cv string) (channelVersion, error) {
63 parts := strings.Split(cv, "-")
64 if len(parts) < 2 {
65 return channelVersion{}, fmt.Errorf("unsupported version format: %s", cv)
66 }
67
68 channel := parts[0]
69 version := parts[1]
70 var hotpatch *int64
71
72 for _, part := range parts[2:] {
73 if i, err := strconv.ParseInt(part, 10, 64); err == nil {
74 hotpatch = &i
75 break
76 }
77 }
78
79 return channelVersion{channel, version, hotpatch, cv}, nil
80 }
81
82
83
84 func IsReleaseChannel(version string) (bool, error) {
85 cv, err := parseChannelVersion(version)
86 if err != nil {
87 return false, err
88 }
89 return cv.channel == "edge" || cv.channel == "stable", nil
90 }
91
View as plain text