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
package xml
import (
"encoding/xml"
"io"
)
type XMLMap map[string]string
type XMLMapEntry struct {
XMLName xml.Name
Value string `xml:",chardata"`
}
// UnmarshalXML
func (m *XMLMap) UnmarshalXML(dec *xml.Decoder, start xml.StartElement) error {
v := XMLMap{}
for {
var e XMLMapEntry
err := dec.Decode(&e)
if err == io.EOF {
break
}
if err != nil {
return err
}
v[e.XMLName.Local] = e.Value
}
*m = v
return nil
}
What did you expect to see?
go vet ./...
< no output>
What did you see instead?
$ go vet ./...
./xml.go:16: method UnmarshalXML(dec *xml.Decoder, start xml.StartElement) error should have signature UnmarshalXML(*xml.Decoder, xml.StartElement) error
even if I try to alias encoding/xml import I still get same error.
If instead I have the same code, but rename package:
package something
...
<same code as before>
go vet ./...
< no output>
go vet doesn't seem to handle correctly if code is in package also named xml.
The text was updated successfully, but these errors were encountered:
I have a very similar issue. I have a package named github.com/mywork/myservice/encoding/json and I have my own Unmarshaler interface.
// Marshaler allows a type to force how it is encoded, given it knows how do the JSON Schema encoding and return
// its schemaID.
type Marshaler interface {
// MarshalJSON knows the schemaID and how to encode itself in JSON format.
MarshalJSON() (encodedBytes []byte, schemaID int, err error)
}
I get the following.
go vet ./...
# github.com/mywork/myservice/encoding/json
encoding/json/encode.go:17:2: method MarshalJSON() (encodedBytes []byte, schemaID int, err error) should have signature MarshalJSON() ([]byte, error)
For my code, I require a schemaID to be returned. We have many different types (Avro, JSON, plaintext, Protobuf) and each of them have their own Marshaler. They all exist within our project github.com/mywork/myservice/encoding/* package. The error is not thrown for the other types, assuming because they have (not std lib) MarshalAvro and MarshalProto methods.
Is there any workaround for this? The only one I currently see is to disable the -stdmethods on go vet.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
For example, if I have the following package:
What did you expect to see?
What did you see instead?
even if I try to alias
encoding/xml
import I still get same error.If instead I have the same code, but rename package:
go vet doesn't seem to handle correctly if code is in package also named xml.
The text was updated successfully, but these errors were encountered: