forgejo-sdk/gitea/user.go

54 lines
1.4 KiB
Go
Raw Normal View History

2014-11-14 22:07:41 +00:00
// Copyright 2014 The Gogs Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
2015-08-26 14:34:27 +01:00
package gitea
2014-11-14 22:07:41 +00:00
import (
"encoding/json"
"fmt"
)
2017-11-12 09:10:33 +00:00
// User represents a user
// swagger:model
2014-11-14 22:07:41 +00:00
type User struct {
2017-11-12 09:10:33 +00:00
// the user's id
ID int64 `json:"id"`
2017-11-12 09:10:33 +00:00
// the user's username
UserName string `json:"login"`
2017-11-12 09:10:33 +00:00
// the user's full name
FullName string `json:"full_name"`
2017-11-12 09:10:33 +00:00
// swagger:strfmt email
Email string `json:"email"`
2017-11-12 09:10:33 +00:00
// URL to the user's avatar
2016-11-10 09:44:00 +00:00
AvatarURL string `json:"avatar_url"`
2018-05-01 12:15:19 +01:00
// User locale
Language string `json:"language"`
2019-03-03 18:34:16 +00:00
// Is the user an administrator
IsAdmin bool `json:"is_admin"`
2014-11-14 22:07:41 +00:00
}
// 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})
}
2016-11-10 09:44:00 +00:00
// GetUserInfo get user info by user's name
func (c *Client) GetUserInfo(user string) (*User, error) {
u := new(User)
err := c.getParsedResponse("GET", fmt.Sprintf("/users/%s", user), nil, nil, u)
return u, err
}
// GetMyUserInfo get user info of current user
func (c *Client) GetMyUserInfo() (*User, error) {
u := new(User)
err := c.getParsedResponse("GET", "/user", nil, nil, u)
return u, err
}