Elba Nanero
Elba Nanero

Reputation: 537

not compatible with reflect.StructTag.Get

I was working in Google CLoud and all was fine.. but when I clone all my project in my PC, I have this messages in every JSON struct.

struct field tag bson:"edad" json:"edad, omitempty" not compatible with reflect.StructTag.Get: suspicious space in struct tag valuestructtag

This is my Struct

type Usuario struct {
    ID        bson.RawValue `bson:"_id" json:"id, omitempty"`
    Nombre    string        `bson:"nombre" json:"nombre, omitempty"`
    Apellidos string        `bson:"apellidos" json:"apellidos, omitempty"`
    Edad      int           `bson:"edad" json:"edad, omitempty"`
    Email     string        `bson:"email" json:"email"`
    Password  string        `bson:"password" json:"password, omitempty"`
}

What's wrong ?

Thanks

Upvotes: 32

Views: 36435

Answers (3)

YellowStrawHatter
YellowStrawHatter

Reputation: 948

Another possible cause of this warning is a missing quotation marks:

Wrong:

Data    interface{} `json:data`

To resolve this, ensure the field tag is properly formatted with quotes, as shown below:

Correct:

Data    interface{} `json:"data"`

Upvotes: 0

Priyansh jain
Priyansh jain

Reputation: 1422

For me the space after the : (colon) was causing this issue. So, remove the space after the colon (:) and also check if you have put "" (inverted commas) properly as it gets mixed with ` sometimes.

Wrong:

Data    interface{} `json: "data,omitempty"`

Correct:

Data    interface{} `json:"data,omitempty"`

So, there should be no spaces when you write anyhthing inside ``.

Upvotes: 2

Pradip Parmar
Pradip Parmar

Reputation: 631

Remove the space after the comma before omitempty, then the error message will go away.

bson:"password" json:"password,omitempty" (should be like this)

In addition, this is a warning not an error. You should still be able to run your project.

Upvotes: 53

Related Questions