-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsafePushing.go
More file actions
43 lines (39 loc) · 1.31 KB
/
safePushing.go
File metadata and controls
43 lines (39 loc) · 1.31 KB
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
package astra
// AddReturnType adds a return type to a slice of return types if it doesn't already exist.
// It uses the field type, package and status code to determine if the return type already exists.
func AddReturnType(prev []ReturnType, n ...ReturnType) []ReturnType {
for _, newReturn := range n {
if len(prev) == 0 {
prev = append(prev, newReturn)
} else {
for _, existingReturn := range prev {
if newReturn.Field.Type != existingReturn.Field.Type || newReturn.Field.Package != existingReturn.Field.Package || newReturn.StatusCode != existingReturn.StatusCode || newReturn.ContentType != existingReturn.ContentType {
prev = append(prev, newReturn)
break
}
}
}
}
return prev
}
// AddComponent adds a component to a slice of components if it doesn't already exist.
// It uses the field type and package to determine if the component already exists.
func AddComponent(prev []Field, n ...Field) []Field {
for _, newComponent := range n {
if len(prev) == 0 {
prev = append(prev, newComponent)
} else {
var found bool
for _, existingComponent := range prev {
if newComponent.Name == existingComponent.Name && newComponent.Package == existingComponent.Package {
found = true
break
}
}
if !found {
prev = append(prev, newComponent)
}
}
}
return prev
}