Skip to content

Commit 2040be8

Browse files
committed
user: replace MarshalJSON with a legacy field
MarshalJSON causes side effect when use *User as embeded struct gogs/gogs#5538.
1 parent 0c04027 commit 2040be8

File tree

2 files changed

+3
-14
lines changed

2 files changed

+3
-14
lines changed

gogs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
)
1515

1616
func Version() string {
17-
return "0.12.13"
17+
return "0.12.14"
1818
}
1919

2020
// Client represents a Gogs API client.

user.go

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,19 @@
55
package gogs
66

77
import (
8-
"encoding/json"
98
"fmt"
109
)
1110

1211
// User represents a API user.
1312
type User struct {
1413
ID int64 `json:"id"`
15-
UserName string `json:"login"`
14+
UserName string `json:"username"` // LEGACY [Gogs 1.0]: remove field(s) for backward compatibility
15+
Login string `json:"login"`
1616
FullName string `json:"full_name"`
1717
Email string `json:"email"`
1818
AvatarUrl string `json:"avatar_url"`
1919
}
2020

21-
// MarshalJSON implements the json.Marshaler interface for User
22-
func (u User) MarshalJSON() ([]byte, error) {
23-
// Re-declaring User to avoid recursion
24-
type shadow User
25-
return json.Marshal(struct {
26-
shadow
27-
// LEGACY [Gogs 1.0]: remove field(s) for backward compatibility
28-
CompatUserName string `json:"username"`
29-
}{shadow(u), u.UserName})
30-
}
31-
3221
func (c *Client) GetUserInfo(user string) (*User, error) {
3322
u := new(User)
3423
err := c.getParsedResponse("GET", fmt.Sprintf("/users/%s", user), nil, nil, u)

0 commit comments

Comments
 (0)