github / github/codeql

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

未關閉
#17,134 5 則留言 1 個 reaction 已指派 0 人 在 GitHub 檢視
question
主要語言
CodeQL
星號
10.1k
分支
2.1k
平均合併
2 天 15 小時
30 天內合併 PR
141

描述

**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.

貢獻指南

開啟貢獻指南

研究方向

從巢狀 struct 範例以及 issue 對 typedecl、idents、匯入路徑和檔案路徑的引用開始。確定查詢應如何處理指標、切片、映射、選擇器和巢狀映射;完成的標準是能夠識別本機型別和匯入型別的宣告;未指定檔案或測試。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
go
領域
devtools
Issue 類型
功能
難度
5/5
預估耗時
一週以上
活躍度
停滯
描述清晰度
需要釐清
新手友好度
20/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。