[英]What's the meaning of [“”] in go
I see this in the range loop to get a MIME header.我在范围循环中看到了这一点,以获得 MIME header。
for _, ext := range parseExtensions(r.Header) {
if ext[""] != "permessage-deflate" {
continue
}
compress = true
break
}
"
characters are used to quote strings. So ""
is an empty string. "
字符用于引用字符串。因此""
是一个空字符串。
[]
is used to reference an element of a map, slice, or array. []
用于引用 map、切片或数组的元素。 In your case, it's a map.在您的情况下,它是 map。
So ext[""]
is referencing the key of map ext
with name ""
.所以ext[""]
引用了名为""
的 map ext
的密钥。 Assuming ext
is a map with a string
key, such as map[string]interface{}
or map[string]string
, it will work fine.假设ext
是带有string
键的 map,例如map[string]interface{}
或map[string]string
,它将正常工作。 Any other type will result in a compilation error.任何其他类型都会导致编译错误。
Based on context, we can assume that it is a map[string]string
, since the value read from the map is being compared to a string.根据上下文,我们可以假设它是一个map[string]string
,因为从 map 读取的值正在与一个字符串进行比较。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.