-
Notifications
You must be signed in to change notification settings - Fork 1
/
checking.go
51 lines (46 loc) · 1.13 KB
/
checking.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
package goease
import (
"strconv"
"strings"
"time"
)
// Check if Int is in Slice
// Example usage:
// intSlice := []int{10, 20, 30, 40}
// intContains := IntContains(intSlice, 20)
// fmt.Println("Slice contains 20:", intContains)
func IntContains(slice []int, element int) bool {
for _, item := range slice {
if item == element {
return true
}
}
return false
}
// Trim String Spaces
// Example usage:
// trimmed := TrimSpaces(" hello world ")
// fmt.Println("Trimmed string:", trimmed)
func TrimSpaces(str string) string {
return strings.TrimSpace(str)
}
// Convert String to Boolean
// Example usage:
// b, err := StringToBool("true")
//
// if err != nil {
// fmt.Println("Error converting string to bool:", err)
// } else {
//
// fmt.Println("Converted boolean:", b)
// }
func StringToBool(str string) (bool, error) {
return strconv.ParseBool(str)
}
// Format Unix Time to String
// Example usage:
// formattedTime := FormatUnixTime(1609459200, "2006-01-02 15:04:05")
// fmt.Println("Formatted time:", formattedTime)
func FormatUnixTime(unixTime int64, layout string) string {
return time.Unix(unixTime, 0).Format(layout)
}