-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.go
48 lines (44 loc) · 1.06 KB
/
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
package crud_module
import (
"net/http"
)
func FindMethod(v ReqVerb) ([]string, error) {
switch v {
case GET:
return []string{http.MethodGet}, nil
case READ:
return []string{"READ"}, nil
case CREATE:
return []string{"CREATE"}, nil
case POST:
return []string{http.MethodPost}, nil
case UPDATE:
return []string{"UPDATE"}, nil
case PUT:
return []string{http.MethodPut}, nil
case DELETE:
return []string{http.MethodDelete}, nil
case CONNECT:
return []string{http.MethodConnect}, nil
case PATCH:
return []string{http.MethodPatch}, nil
case TRACE:
return []string{http.MethodTrace}, nil
case CRUD:
return []string{"CREATE", "READ", "UPDATE", http.MethodDelete}, nil
}
return []string{"UNKNOWN"}, http.ErrNotSupported
}
func RemoveItemsFromArray(arr []string, itemsToRemove []string) []string {
result := []string{}
itemsToRemoveMap := make(map[string]bool)
for _, item := range itemsToRemove {
itemsToRemoveMap[item] = true
}
for _, item := range arr {
if !itemsToRemoveMap[item] {
result = append(result, item)
}
}
return result
}