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

Backward compatibility (username vs. login) #28

Merged
merged 1 commit into from
Dec 16, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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