woodpecker/remote/coding/internal/user.go
2017-07-22 17:12:09 +08:00

25 lines
482 B
Go

package internal
import (
"encoding/json"
)
type User struct {
GlobalKey string `json:"global_key"`
Email string `json:"email"`
Avatar string `json:"avatar"`
}
func (c *Client) GetCurrentUser() (*User, error) {
u := "/account/current_user"
resp, err := c.Get(u, nil)
if err != nil {
return nil, err
}
user := &User{}
err = json.Unmarshal(resp, user)
if err != nil {
return nil, APIClientErr{"fail to parse current user data", u, err}
}
return user, nil
}