[zeromicro/go-zero]http 请求参数解析报错

2023-12-25 390 views
1

请求中带有数组,如:GET /book/add?name=a&name=b&name=c,解析报错。 看了下源码,解析参数时使用了如下函数:

type Values map[string][]string

// Get gets the first value associated with the given key.
// If there are no values associated with the key, Get returns
// the empty string. To access multiple values, use the map
// directly.
func (v Values) Get(key string) string {
    if v == nil {
        return ""
    }
    vs := v[key]
    if len(vs) == 0 {
        return ""
    }
    return vs[0]
}

请问之后会解决这个问题吗?如果解决的话会在多久之后的版本呢?

回答

2

这个是Go的吧,我解决不了呢

而且你这个用户不规范哈

6

在requests.go文件的ParseForm方法,下面的处理感觉应该不能饿用r.Form.Get()来取值,因为get只取一个元素。

params := make(map[string]interface{}, len(r.Form)) for name := range r.Form { formValue := r.Form.Get(name) if len(formValue) > 0 { params[name] = formValue } }

5

框架层面如果能支持逗号分割的数组解析,就很方便

我自己写的解析,支持type_ids=1,2,3,4 这种格式