...
1 package utils
2
3 import (
4 "bytes"
5 "strings"
6 )
7
8 type Unit struct {
9 Value string
10 Label string
11 }
12
13 func CheckString(s *string) string {
14 return ConvertToString(s)
15 }
16
17 func ConvertToString(s *string) string {
18 if s != nil {
19 return *s
20 }
21
22 return ""
23 }
24
25 func ConvertToInt(i *int) int {
26 if i != nil {
27 return *i
28 }
29
30 return 0
31 }
32
33 func ConvertToFloat64(f *float64) float64 {
34 if f != nil {
35 return *f
36 }
37
38 return 0.0
39 }
40
41 func ConvertToBool(b *bool) bool {
42 if b != nil {
43 return *b
44 }
45
46 return false
47 }
48
49 func IsNullOrEmpty(s *string) bool {
50 return s == nil || strings.TrimSpace(*s) == ""
51 }
52
53 func URLCheck(username, password, repoURL string) bool {
54 return strings.Contains(repoURL, "ncr") && username == "" && password == ""
55 }
56
57 func IsValidJSONObject(js []byte) bool {
58 jsString := bytes.TrimLeft(js, " \t\r\n")
59
60 return len(jsString) > 0 && jsString[0] == '{'
61 }
62
63 func Contains(arr []string, str string) bool {
64 for _, v := range arr {
65 if v == str {
66 return true
67 }
68 }
69 return false
70 }
71
72 func Reject(arr []string, str string) []string {
73 var result []string
74 for _, item := range arr {
75 if str != item {
76 result = append(result, item)
77 }
78 }
79 return result
80 }
81
View as plain text