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

Commit

Permalink
Backward compatibility (username vs. login)
Browse files Browse the repository at this point in the history
Reintroduce the username field for user object on JSON marshal to fix backward
compatibility. Fixes Drone 0.4 compatibility issues.
  • Loading branch information
martinhpedersen authored and bkcsoft committed Dec 16, 2016
1 parent 559190d commit 76837c0
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions gitea/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package gitea

import (
"encoding/json"
"fmt"
)

Expand All @@ -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)
Expand Down

0 comments on commit 76837c0

Please sign in to comment.