/
split.go
29 lines (26 loc) · 917 Bytes
/
split.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
package vercel
import "strings"
// splitInto2Or3 is a helper function for splitting an import ID into the corresponding parts.
// It also validates whether the ID is in a correct format.
func splitInto2Or3(id string) (teamID, firstID, secondID string, ok bool) {
attributes := strings.Split(id, "/")
if len(attributes) == 2 {
return "", attributes[0], attributes[1], true
}
if len(attributes) == 3 {
return attributes[0], attributes[1], attributes[2], true
}
return "", "", "", false
}
// splitInto1Or2 is a helper function for splitting an import ID into the corresponding parts.
// It also validates whether the ID is in a correct format.
func splitInto1Or2(id string) (teamID, firstID string, ok bool) {
if strings.Contains(id, "/") {
attributes := strings.Split(id, "/")
if len(attributes) != 2 {
return "", "", false
}
return attributes[0], attributes[1], true
}
return "", id, true
}