-
Notifications
You must be signed in to change notification settings - Fork 0
/
paas_cmpt_ver.go
75 lines (60 loc) · 1.35 KB
/
paas_cmpt_ver.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package proto
import (
"strings"
"github.com/maoge/paas-metasvr-go/pkg/consts"
)
type PaasCmptVer struct {
SERV_TYPE string `db:"SERV_TYPE"`
VERSION string `db:"VERSION"`
VER_LIST []string
}
func NewPaasCmptVer(servType string, version string) *PaasCmptVer {
cmptVer := new(PaasCmptVer)
cmptVer.SERV_TYPE = servType
cmptVer.VERSION = version
cmptVer.InitVerList()
return cmptVer
}
func (m *PaasCmptVer) InitVerList() {
s := strings.Trim(m.VERSION, " ")
m.VER_LIST = make([]string, 0)
m.VER_LIST = append(m.VER_LIST, s)
}
func (m *PaasCmptVer) AddVersion(version string) {
m.VER_LIST = append(m.VER_LIST, version)
}
func (m *PaasCmptVer) DelVersion(version string) {
length := len(m.VER_LIST)
if length == 0 {
return
}
tmp := make([]string, length-1)
for _, s := range m.VER_LIST {
if s == version {
continue
}
tmp = append(tmp, s)
}
m.VER_LIST = tmp
}
func (m *PaasCmptVer) IsVersionExist(ver string) bool {
for _, v := range m.VER_LIST {
if ver == v {
return true
}
}
return false
}
func (m *PaasCmptVer) ToJsonMap() map[string]interface{} {
versionSlice := ""
for _, s := range m.VER_LIST {
if versionSlice != "" {
versionSlice += ","
}
versionSlice += s
}
result := make(map[string]interface{})
result[consts.HEADER_SERV_TYPE] = m.SERV_TYPE
result[consts.HEADER_VERSION] = versionSlice
return result
}