我无法验证传递给POST端点的JSON正文是否与为可接受的JSON正文创建的结构匹配。任何帮助将不胜感激
type NewUser struct {
UserID string `json:"user_id"`
username string `json:"user_name"`
}
func AddUser(w http.ResponseWriter,r *http.Request) {
w.Header().Set("Content-Type","application/json")
decoder := json.NewDecoder(r.Body)
var user NewUser
err := decoder.Decode(&user)
if err != nil {
http.Error(w,err.Error(),http.StatusBadRequest)
}
user.UserID != NewUser.UserID{
http.Error(w,"error",http.StatusBadRequest),}
}