sheriff icon indicating copy to clipboard operation
sheriff copied to clipboard

Cause bug when have struct method

Open j796160836 opened this issue 4 years ago • 0 comments

Hi, I found a bug when a structure having method. For the example,

Find the User struct in sample code

type User struct {
	Username string   `json:"username" groups:"api"`
	Email    string   `json:"email"`
	Name     string   `json:"name" groups:"api"`
	Roles    []string `json:"roles" groups:"api"`
}

Add the following code below,

func (u User) String() string {
	return fmt.Sprintf("User<%s %s>", u.Username, u.Name)
}

It will brick the scoping, marshal all the stuff into json.

j796160836 avatar Jun 14 '21 12:06 j796160836