You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

user.go 977B

123456789101112131415161718192021222324252627282930313233343536
  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 gitea
  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. // GetUserInfo get user info by user's name
  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. }