-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.go
50 lines (42 loc) · 896 Bytes
/
utils.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
package common
import "golang.org/x/exp/constraints"
type Map = map[string]any
func Max[T constraints.Ordered](a, b T) T {
if a > b {
return a
}
return b
}
func Min[T constraints.Ordered](a, b T) T {
if a < b {
return a
}
return b
}
func Keys[T comparable, S any](m map[T]S) (s []T) {
for k := range m {
s = append(s, k)
}
return s
}
func Values[T comparable, S any](m map[T]S) (s []S) {
for _, v := range m {
s = append(s, v)
}
return s
}
func StripContent(content string, contentMaxSize int) string {
contentRune := []rune(content)
contentRuneLength := len(contentRune)
if contentRuneLength <= contentMaxSize {
return content
}
return string(contentRune[:contentMaxSize])
}
func StripBytes(content []byte, contentMaxSize int) []byte {
contentLength := len(content)
if contentLength <= contentMaxSize {
return content
}
return content[:contentMaxSize]
}