Skip to content
This repository was archived by the owner on Jun 8, 2019. It is now read-only.

Commit 76837c0

Browse files
martinhpedersenbkcsoft
authored andcommitted
Backward compatibility (username vs. login)
Reintroduce the username field for user object on JSON marshal to fix backward compatibility. Fixes Drone 0.4 compatibility issues.
1 parent 559190d commit 76837c0

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

gitea/user.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package gitea
66

77
import (
8+
"encoding/json"
89
"fmt"
910
)
1011

@@ -17,6 +18,16 @@ type User struct {
1718
AvatarURL string `json:"avatar_url"`
1819
}
1920

21+
// MarshalJSON implements the json.Marshaler interface for User, adding field(s) for backward compatibility
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+
CompatUserName string `json:"username"`
28+
}{shadow(u), u.UserName})
29+
}
30+
2031
// GetUserInfo get user info by user's name
2132
func (c *Client) GetUserInfo(user string) (*User, error) {
2233
u := new(User)

0 commit comments

Comments
 (0)