user.go 955 B

12345678910111213141516171819202122232425262728293031323334353637
  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
  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. // LEGACY [Gogs 1.0]: remove field(s) for backward compatibility
  24. CompatUserName string `json:"username"`
  25. }{shadow(u), u.UserName})
  26. }
  27. func (c *Client) GetUserInfo(user string) (*User, error) {
  28. u := new(User)
  29. err := c.getParsedResponse("GET", fmt.Sprintf("/users/%s", user), nil, nil, u)
  30. return u, err
  31. }