html/template: How to bind nested structs from form data?
まだ誰も着手していません。
評価
調査の方向性
例の c.Bind 呼び出しから始め、リポジトリがリクエストフォームのパースとネストされた値をどのように処理しているかを調べてください。その動作を標準ライブラリのフォームデータに関する規約と比較し、想定される命名規約がサポートされているかどうか、またその結果がドキュメント化または範囲を限定した機能提案を必要とするかどうかを判断してください。
索引モデルが issue の本文から書いたものです。
説明
I'm trying to bind form data to nested structs, but I'm not sure if I'm doing it correctly. Is there a recommended way to handle form binding with nested structs using the standard library?
My Use Case
I have a form structure with nested fields that I want to bind to corresponding nested structs:
type UserInfo struct {
Name string `form:"name"`
Sex string `form:"sex"`
}
type UserGroup struct {
Men []UserInfo `form:"men"`
Women []UserInfo `form:"women"`
}
type UserResults struct {
Win UserGroup `form:"win"`
Lose UserGroup `form:"lose"`
}
func handler(w http.ResponseWriter, r *http.Request) {
form := &UserResults{}
if err := c.Bind(form); err != nil {
// error handle
}
// Values are not bound to nested structs
}
What I've Tried
I've attempted to use dot notation in the form field names:
<form method="POST">
<input type="number" name="win.men[0].name" value="john">
<input type="number" name="win.men[0].sex" value="1">
</form>
Questions
- Is there a built-in way to handle nested struct binding with the standard library?
- If yes, what is the correct naming convention for form fields?
- Is there any documentation I might have missed about this topic?
Environment
- Go version: 1.22
Any guidance or best practices would be greatly appreciated. If this functionality isn't currently supported, would it be worth considering as a feature request?
- 主要言語
- Go
- スター
- 32.7k
- フォーク
- 2.8k
- 平均マージ
- 9時間 39分
- マージ済み PR(30日)
- 6
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
labstack/echo のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 65/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 68/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 74/100
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
似ている issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 60/100
github/gh-aw-mcpg#13748 ·
-
agentic-workflows
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
-
needs-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
googleapis/librarian#7670 · コメント 2 件 ·