英文:
Passing an array/slice as a url parameter
问题
我有一个简单的Web服务器,拦截地理空间地图瓦片请求,替换像素,并将图像传递给前端进行服务。它运行得很好,但请求变得相当大。我想知道是否可以传递一个数组或切片来代替?我在搜索中找不到相关信息。例如:
http://localhost:8002/tiles?url=url&r=0&g=250&b=0&a=230&replaceR=0&replaceG=127&replaceB=0&replaceA=0
是我典型的请求。我想要添加更多的颜色进行替换,所以如果我可以传递类似这样的内容就太好了:
http://localhost:8002/tiles?url=url&rgba1=[0,250,0,230,0,127,0,0]&rgba2=[250,0,100,100,200,0,20,180]
这种方式可行吗?我尝试使用循环来实现:
form := make(map[string][]uint8)
for k, v := range r.URL.Query() {
arr := []uint8{}
for i := 0; i < len(v); i++ {
val, err := strconv.ParseInt(v[i], 10, 32)
arr = append(arr, uint8(val))
if err != nil {
}
}
form[k] = arr
}
但它只打印出 [0]。
英文:
I have a simple web server that intercepts geospatial map tile requests, swaps out pixels, and passes the image along to a front end to serve them. It works great, but the request is getting quite large. I was wondering if I could pass an array or slice instead? I couldn't seem to find anything searching. For example:
http://localhost:8002/tiles?url=url&r=0&g=250&b=0&a=230&replaceR=0&replaceG=127&replaceB=0&replaceA=0
is my typical request. I want to add more colors to swap so it would be great if I could pass something like:
http://localhost:8002/tiles?url=url&rgba1=[0,250,0,230,0,127,0,0]&rgba2=[250,0,100,100,200,0,20,180]
Is this possible? I tried to loop it like:
form := make(map[string][]uint8)
for k, v := range r.URL.Query() {
arr := []uint8{}
for i := 0; i < len(v); i++ {
val, err := strconv.ParseInt(v[i], 10, 32)
arr = append(arr, uint8(val))
if err != nil {
}
}
form[k] = arr
}
But it just prints [0]
答案1
得分: 5
你的GET请求中的参数不是数组。
rgba1=0&rgba1=250&rgba1=0&rgba1=230&rgba1=0&rgba1=127&rgba1=0&rgba1=0
将其转换为数组形式:rgba1=[0,250,0,230,0,127,0,0]
参考链接:https://golang.org/pkg/net/url/#Values
英文:
Your parameters in GET request aren't arrays.
rgba1=0&rgba1=250&rgba1=0&rgba1=230&rgba1=0&rgba1=127&rgba1=0&rgba1=0
Creates an array rgba1=[0,250,0,230,0,127,0,0]
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论