Skip to content

Commit c78b2e0

Browse files
authored
Merge pull request #32 from subomi/subomi/feat/core-improvements
2 parents dadbc02 + eb350ba commit c78b2e0

5 files changed

Lines changed: 1453 additions & 403 deletions

File tree

.github/workflows/go.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,8 @@ jobs:
3939
- name: Go vet
4040
run: go vet ./...
4141

42+
- name: Run race detector
43+
run: go build -race ./...
44+
4245
- name: Run tests
4346
run: go test ./...

common.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package requestmigrations
2+
3+
import (
4+
"reflect"
5+
"strings"
6+
)
7+
8+
// IsStringEmpty checks if the given string s is empty or not
9+
func isStringEmpty(s string) bool { return len(strings.TrimSpace(s)) == 0 }
10+
11+
// dereferenceToLastPtr dereferences nested pointers down to the last pointer level.
12+
// For example: ***T -> *T, **T -> *T, *T -> *T, T -> T
13+
func dereferenceToLastPtr(t reflect.Type) reflect.Type {
14+
if t.Kind() == reflect.Ptr && t.Elem().Kind() == reflect.Ptr {
15+
return dereferenceToLastPtr(t.Elem())
16+
}
17+
return t
18+
}
19+
20+
// typeHasInterfaceFields checks if a type has any interface fields (direct or nested).
21+
// Types with interface fields need runtime value inspection and cannot use cached graphs directly.
22+
func typeHasInterfaceFields(t reflect.Type) bool {
23+
return typeHasInterfaceFieldsRecursive(t, make(map[reflect.Type]bool))
24+
}
25+
26+
func typeHasInterfaceFieldsRecursive(t reflect.Type, visited map[reflect.Type]bool) bool {
27+
// Dereference pointers
28+
for t.Kind() == reflect.Ptr {
29+
t = t.Elem()
30+
}
31+
32+
// Prevent infinite recursion for cyclic types
33+
if visited[t] {
34+
return false
35+
}
36+
visited[t] = true
37+
38+
switch t.Kind() {
39+
case reflect.Interface:
40+
return true
41+
case reflect.Struct:
42+
for i := 0; i < t.NumField(); i++ {
43+
if typeHasInterfaceFieldsRecursive(t.Field(i).Type, visited) {
44+
return true
45+
}
46+
}
47+
case reflect.Slice, reflect.Array:
48+
return typeHasInterfaceFieldsRecursive(t.Elem(), visited)
49+
case reflect.Map:
50+
return typeHasInterfaceFieldsRecursive(t.Key(), visited) ||
51+
typeHasInterfaceFieldsRecursive(t.Elem(), visited)
52+
}
53+
54+
return false
55+
}

0 commit comments

Comments
 (0)