forked from raystack/guardian
-
Notifications
You must be signed in to change notification settings - Fork 2
/
utils.go
39 lines (33 loc) · 906 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
package utils
import (
"fmt"
"github.com/google/uuid"
)
func IsInteger(val float64) bool {
return val == float64(int(val))
}
// MapToSlice converts map[string]string to []string
//
// Example:
//
// Input: map[string]string{ "key1": "value1", "key2": "value2", "key3": "value3"}
// Output: []string{"key1=value1", "key2=value2", "key3=value3"}
func MapToSlice(m map[string]string) []string {
s := make([]string, len(m))
i := 0
for k, v := range m {
s[i] = k + "=" + v
i++
}
return s
}
// IsValidUUID returns true if uuid is valid
func IsValidUUID(u string) bool {
_, err := uuid.Parse(u)
return err == nil
}
// GetGlobalURN returns a GlobalURN for a given source, scope, kind and identifier
// format is urn:<source>:<scope>:<kind>:<identifier>
func GetGlobalURN(source, scope, kind, identifier string) string {
return fmt.Sprintf("urn:%s:%s:%s:%s", source, scope, kind, identifier)
}