背景
在使用golang的struct tag进行json和db映射的时候,发现有这么一行和其它不一样,本以为是冒号或者分号中英文不对的问题,但是细细寻找一遍之后无果,这一行就一直报这个错误,很尴尬,明明和其它行的用法一样,但就是有这种警告,而且程序运行时也确实映射不到,最后找到了错误,是空格的tab的区别。。。。
没错,这里只能用空格,不能用tab。。。就是如此坑。。。。但是goland IDE早已帮你想到了解决办法,smart tab 哈哈,设置方法见最后一张图。
Bad syntax for struct tag value less… (⌘F1)
Inspection info: Verifies that struct tags conform to Go conventions.
According to these conventions, tag strings are a concatenation of optionally space-separated key:”value” pairs. Each key is a non-empty string consisting of non-control characters other than space (U+0020 ’ ‘), quote (U+0022 ‘”’), and colon (U+003A ‘:’). Each value is quoted using U+0022 ‘”’ characters and Go string literal syntax.
Also, checks that fields with tags are exported.
解决
然后删除中间的tab,再次敲tab就是4个空格了。done :)