Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

html/template: How to bind nested structs from form data?

オープン
#2,746 コメント 1 件 リアクション 5 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
35/100
issue の種類
機能追加
明瞭さ
説明が足りない
活発さ
活発
技術スタック
go
領域
api, backend

調査の方向性

例の 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

  1. Is there a built-in way to handle nested struct binding with the standard library?
  2. If yes, what is the correct naming convention for form fields?
  3. 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

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

labstack/echo のほかの issue

labstack/echo の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。