Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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

Đang mở
#2,746 1 bình luận 5 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
35/100
Loại issue
Tính năng
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Sôi nổi
Công nghệ
go
Lĩnh vực
api, backend

Hướng nghiên cứu

Bắt đầu tại lệnh gọi c.Bind trong ví dụ và kiểm tra cách repository xử lý việc phân tích cú pháp form của request và các giá trị lồng nhau. So sánh hành vi đó với các quy ước về dữ liệu form của thư viện chuẩn, sau đó xác định liệu quy ước đặt tên dự kiến có được hỗ trợ hay không và liệu kết quả có cần tài liệu hay một đề xuất tính năng có phạm vi giới hạn hay không.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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?

Ngôn ngữ chính
Go
Star
32.7k
Fork
2.8k
Merge trung bình
9 giờ 39 phút
Pull request đã merge (30 ngày)
6

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của labstack/echo

Tất cả issue của labstack/echo

Issue tương tự

Thêm issue về Go

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.