github / github/codeql

Writing a query to find declarations of nested structs in Golang.

Offen
#17,134 5 Kommentare 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen
question
Vorherrschende Sprache
CodeQL
Sterne
10.1k
Forks
2.1k
Ø Merge
2 T. 15 Std.
Gemergte PRs (30 T.)
141

Beschreibung

**Description of the issue**

I want to write a query to find the nested structs in an struct in Golang.
Let's say my struct is something like:
```
type SomeStruct struct {
field1 int
field2 dto.NewStruct
field3 []*statusCode
field4 map[string]http.Response
field5 map[category.Category]map[time.Time]*http.Header
field6 []statusCode
field7 []*time.Time
field8 http.Request
field9 statusCode
}
```
and I want to write a query that gives me all the nested types in this struct ie. `statusCode,Response,Category,Time,Header,NewStruct` etc.
The field types can be more complex than what is mentioned here.
My main problem statement is to find the declarations of these nested structs, which I will continue my query by finding all `typedecl` with their `idents` matching with the above mentioned `idents` while matching the import path and the filepath for nested objects from different packages like `dto.NewStruct`. If there is some better approach please suggest.
Please suggest me an approach.

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.