-
Notifications
You must be signed in to change notification settings - Fork 45
/
conversion.go
62 lines (52 loc) · 1.33 KB
/
conversion.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
// Copyright The Linux Foundation and each contributor to CommunityBridge.
// SPDX-License-Identifier: MIT
package utils
// StringValue function convert string pointer to string
func StringValue(input *string) string {
if input == nil {
return ""
}
return *input
}
// StringRef function convert string to string reference
func StringRef(input string) *string {
return &input
}
// Int64Value function convert int64 pointer to string
func Int64Value(input *int64) int64 {
if input == nil {
return 0
}
return *input
}
// Int64 returns a pointer to the int64 value passed in.
func Int64(v int64) *int64 {
return &v
}
// BoolValue function convert boolean pointer to boolean
func BoolValue(input *bool) bool {
if input == nil {
return false
}
return *input
}
// Bool function convert boolean to boolean pointer
func Bool(input bool) *bool {
return &input
}
// GetNilSliceIfEmpty returns a nil reference is the specified slice is empty, otherwise returns a reference to the original slice
func GetNilSliceIfEmpty(slice []string) []string {
if len(slice) == 0 {
return nil
}
return slice
}
// ArrayStringPointer converts Array string to Array string pointer
func ArrayStringPointer(input []string) []*string {
var conversion []*string
for _, v := range input {
v2 := v
conversion = append(conversion, &v2)
}
return conversion
}