You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I have noticed a problem with go vet that have stung me recently. Go vet doesn't report an error in the field tag formatting.
Let's take an example struct :
// TestStruct comment
type TestStruct struct {
A string `json:"jsona",xml:"xmla"`
}
As you can see I have set the field tags, and while the tags looks OK, the tag format is incorrect. To illustrate, the example code:
package main
import (
"fmt"
"reflect"
)
// TestStruct comment
type TestStruct struct {
A string `json:"jsona",xml:"xmla"`
}
func main() {
var theStruct = TestStruct{"A"}
fmt.Println("First field tag: ", reflect.TypeOf(theStruct).Field(0).Tag)
fmt.Println("Json tag value: ", reflect.TypeOf(theStruct).Field(0).Tag.Get("json"))
fmt.Println("XML tag value: ", reflect.TypeOf(theStruct).Field(0).Tag.Get("xml"))
}
Did return
First field tag: json:"jsona",xml:"xmla"
Json tag value: jsona
XML tag value:
The problem here is the coma character between json and xml tags.
The go vet tool doesn't complain about this type of error and I would like to fix it if it is OK.
I will raise a pull request if the maintainers agree that this is a bug in the go vet tool indeed.
The text was updated successfully, but these errors were encountered:
Yes, i think go vet should detect this case. But note that we don't use
pull request, please send a CL instead. See
https://golang.org/doc/contribute.html.
Actually the tags are parseable in this case. The tag json:"jsona",xml:"xmla" is the same as json:"jsona" ,xml:"xmla". That is, there is an entry with key json and an entry with key ,xml. If you did tag.Get(",xml") you could retrieve the second one.
That said, it's obviously a mistake and probably one vet should catch even though it's not technically illegal. Will send a CL.
Hi, I have noticed a problem with
go vet
that have stung me recently.Go vet
doesn't report an error in the field tag formatting.Let's take an example struct :
As you can see I have set the field tags, and while the tags looks OK, the tag format is incorrect. To illustrate, the example code:
Did return
The problem here is the coma character between
json
andxml
tags.The go vet tool doesn't complain about this type of error and I would like to fix it if it is OK.
I will raise a pull request if the maintainers agree that this is a bug in the go vet tool indeed.
The text was updated successfully, but these errors were encountered: