Use reflection to dump context
- 主要言語
- 言語のデータがありません
- スター
- 568
- フォーク
- 73
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
Sometimes for local debugging, using [reflection to dump the context](https://stackoverflow.com/a/60278058/2904179) is handy:
```
func printContextInternals(ctx interface{}, inner bool) {
contextValues := reflect.ValueOf(ctx).Elem()
contextKeys := reflect.TypeOf(ctx).Elem()
if !inner {
fmt.Printf("\nFields for %s.%s\n", contextKeys.PkgPath(), contextKeys.Name())
}
if contextKeys.Kind() == reflect.Struct {
for i := 0; i < contextValues.NumField(); i++ {
reflectValue := contextValues.Field(i)
reflectValue = reflect.NewAt(reflectValue.Type(), unsafe.Pointer(reflectValue.UnsafeAddr())).Elem()
reflectField := contextKeys.Field(i)
if reflectField.Name == "Context" {
printContextInternals(reflectValue.Interface(), true)
} else {
fmt.Printf("field name: %+v\n", reflectField.Name)
fmt.Printf("value: %+v\n", reflectValue.Interface())
}
}
} else {
fmt.Printf("context is empty (int)\n")
}
}
```
Thanks for putting all your examples in one central place!
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
調査の方向性
この issue では、Go の context 向けに reflection ベースのデバッグユーティリティを追加することが提案されています。構造と命名を理解するために、リポジトリ内の既存の例を確認してください。提供されている関数は、新しい例のファイルに適用できます。おそらく 'context' や 'debug' のようなディレクトリに配置します。context の内部を調査する方法を示す例がコンパイルおよび実行できることを確認してください。例がどのように検証されているかを確認するために、既存のテストがあるかどうかを確認してください。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- go
- 領域
- documentation
- issue の種類
- ドキュメント
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 75/100