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.
This commit is contained in:
parent
559190dbdc
commit
76837c0ea4
1 changed files with 11 additions and 0 deletions
|
@ -5,6 +5,7 @@
|
|||
package gitea
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
|
@ -17,6 +18,16 @@ type User struct {
|
|||
AvatarURL string `json:"avatar_url"`
|
||||
}
|
||||
|
||||
// MarshalJSON implements the json.Marshaler interface for User, adding field(s) for backward compatibility
|
||||
func (u User) MarshalJSON() ([]byte, error) {
|
||||
// Re-declaring User to avoid recursion
|
||||
type shadow User
|
||||
return json.Marshal(struct {
|
||||
shadow
|
||||
CompatUserName string `json:"username"`
|
||||
}{shadow(u), u.UserName})
|
||||
}
|
||||
|
||||
// GetUserInfo get user info by user's name
|
||||
func (c *Client) GetUserInfo(user string) (*User, error) {
|
||||
u := new(User)
|
||||
|
|
Loading…
Reference in a new issue