forked from kyma-project/Cx1ClientGo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.go
80 lines (71 loc) · 1.55 KB
/
util.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
76
77
78
79
80
package Cx1ClientGo
import (
"fmt"
"strings"
"time"
)
func ShortenGUID(guid string) string {
if len(guid) <= 2 {
return ".."
}
return fmt.Sprintf("%v..%v", guid[:2], guid[len(guid)-2:])
}
func (c Cx1Client) depwarn(old, new string) {
if new == "" {
c.logger.Warnf("Cx1ClientGo deprecation notice: %v will be deprecated", old)
} else {
c.logger.Warnf("Cx1ClientGo deprecation notice: %v will be deprecated and replaced by %v", old, new)
}
}
func RemoveIndex(slice []interface{}, index int) []interface{} {
ret := slice[:index]
ret = append(ret, slice[index+1:]...)
return ret
}
func RemoveGroup(slice []Group, index int) []Group {
ret := slice[:index]
ret = append(ret, slice[index+1:]...)
return ret
}
func RemoveGroupByID(slice []Group, ID string) []Group {
index := -1
for i, g := range slice {
if g.GroupID == ID {
index = i
break
}
}
if index == -1 {
return slice
}
return RemoveGroup(slice, index)
}
func RemoveRole(slice []Role, index int) []Role {
ret := slice[:index]
ret = append(ret, slice[index+1:]...)
return ret
}
func RemoveRoleByID(slice []Role, ID string) []Role {
index := -1
for i, r := range slice {
if r.RoleID == ID {
index = i
break
}
}
if index == -1 {
return slice
}
return RemoveRole(slice, index)
}
// 2024-08-12T10:57:20.192973906Z
const cx1TimeLayout = "2006-01-02T15:04:05.999999999Z"
func (ct *Cx1LongTime) UnmarshalJSON(b []byte) (err error) {
s := strings.Trim(string(b), "\"")
if s == "null" {
ct.Time = time.Time{}
return
}
ct.Time, err = time.Parse(cx1TimeLayout, s)
return
}