user.go 932 B

1234567891011121314151617181920212223242526272829303132333435
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package gogs
  5. import (
  6. "encoding/json"
  7. "fmt"
  8. )
  9. // User represents a API user.
  10. type User struct {
  11. ID int64 `json:"id"`
  12. UserName string `json:"login"`
  13. FullName string `json:"full_name"`
  14. Email string `json:"email"`
  15. AvatarUrl string `json:"avatar_url"`
  16. }
  17. // MarshalJSON implements the json.Marshaler interface for User, adding field(s) for backward compatibility
  18. func (u User) MarshalJSON() ([]byte, error) {
  19. // Re-declaring User to avoid recursion
  20. type shadow User
  21. return json.Marshal(struct {
  22. shadow
  23. CompatUserName string `json:"username"`
  24. }{shadow(u), u.UserName})
  25. }
  26. func (c *Client) GetUserInfo(user string) (*User, error) {
  27. u := new(User)
  28. err := c.getParsedResponse("GET", fmt.Sprintf("/users/%s", user), nil, nil, u)
  29. return u, err
  30. }