Closed
Description
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.