Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 98046bb

Browse files
martinhpedersenunknwon
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 3693f6a commit 98046bb

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
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.4"
17+
return "0.12.5"
1818
}
1919

2020
// Client represents a Gogs API client.

‎user.go‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package gogs
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
func (c *Client) GetUserInfo(user string) (*User, error) {
2132
u := new(User)
2233
err := c.getParsedResponse("GET", fmt.Sprintf("/users/%s", user), nil, nil, u)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /