本文整理汇总了Golang中github.com/jonnonz1/goth.User.Description方法的典型用法代码示例。如果您正苦于以下问题:Golang User.Description方法的具体用法?Golang User.Description怎么用?Golang User.Description使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/jonnonz1/goth.User
的用法示例。
在下文中一共展示了User.Description方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: FetchUser
// FetchUser will go to Twitter and access basic information about the user.
func (p *Provider) FetchUser(session goth.Session) (goth.User, error) {
user := goth.User{
Provider: p.Name(),
}
sess := session.(*Session)
response, err := p.consumer.Get(
endpointProfile,
map[string]string{"include_entities": "false", "skip_status": "true"},
sess.AccessToken)
if err != nil {
return user, err
}
defer response.Body.Close()
bits, err := ioutil.ReadAll(response.Body)
err = json.NewDecoder(bytes.NewReader(bits)).Decode(&user.RawData)
if err != nil {
return user, err
}
user.Name = user.RawData["name"].(string)
user.NickName = user.RawData["screen_name"].(string)
user.Description = user.RawData["description"].(string)
user.AvatarURL = user.RawData["profile_image_url"].(string)
user.UserID = user.RawData["id_str"].(string)
user.Location = user.RawData["location"].(string)
user.AccessToken = sess.AccessToken.Token
user.AccessTokenSecret = sess.AccessToken.Secret
return user, err
}
示例2: userFromReader
func userFromReader(reader io.Reader, user *goth.User) error {
u := struct {
ID int `json:"id"`
Email string `json:"email"`
Bio string `json:"bio"`
Name string `json:"name"`
Login string `json:"login"`
Picture string `json:"avatar_url"`
Location string `json:"location"`
}{}
err := json.NewDecoder(reader).Decode(&u)
if err != nil {
return err
}
user.Name = u.Name
user.NickName = u.Login
user.Email = u.Email
user.Description = u.Bio
user.AvatarURL = u.Picture
user.UserID = strconv.Itoa(u.ID)
user.Location = u.Location
return err
}
示例3: userFromReader
func userFromReader(reader io.Reader, user *goth.User) error {
u := struct {
Data struct {
ID string `json:"id"`
UserName string `json:"username"`
FullName string `json:"full_name"`
ProfilePicture string `json:"profile_picture"`
Bio string `json:"bio"`
Website string `json:"website"`
Counts struct {
Media int `json:"media"`
Follows int `json:"follows"`
FollowedBy int `json:"followed_by"`
} `json:"counts"`
} `json:"data"`
}{}
err := json.NewDecoder(reader).Decode(&u)
if err != nil {
return err
}
user.Name = u.Data.UserName
user.NickName = u.Data.UserName
user.AvatarURL = u.Data.ProfilePicture
user.Description = u.Data.Bio
return err
}
示例4: userFromReader
func userFromReader(r io.Reader, user *goth.User) error {
u := struct {
Name string `json:"name"`
Email string `json:"email"`
Nickname string `json:"display_name"`
AvatarURL string `json:"logo"`
Description string `json:"bio"`
ID int `json:"_id"`
}{}
err := json.NewDecoder(r).Decode(&u)
if err != nil {
return err
}
user.Name = u.Name
user.Email = u.Email
user.NickName = u.Nickname
user.Location = "No location is provided by the Twitch API"
user.AvatarURL = u.AvatarURL
user.Description = u.Description
user.UserID = strconv.Itoa(u.ID)
return nil
}
示例5: buildUserObject
// buildUserObject is an internal function to build a goth.User object
// based in the data stored in r
func buildUserObject(r io.Reader, u goth.User) (goth.User, error) {
// Response object from Steam
apiResponse := struct {
Response struct {
Players []struct {
UserID string `json:"steamid"`
NickName string `json:"personaname"`
Name string `json:"realname"`
AvatarURL string `json:"avatarfull"`
LocationCountryCode string `json:"loccountrycode"`
LocationStateCode string `json:"locstatecode"`
} `json:"players"`
} `json:"response"`
}{}
err := json.NewDecoder(r).Decode(&apiResponse)
if err != nil {
return u, err
}
if l := len(apiResponse.Response.Players); l != 1 {
return u, fmt.Errorf("Expected one player in API response. Got %d.", l)
}
player := apiResponse.Response.Players[0]
u.UserID = player.UserID
u.Name = player.Name
if len(player.Name) == 0 {
u.Name = "No name is provided by the Steam API"
}
u.NickName = player.NickName
u.AvatarURL = player.AvatarURL
u.Email = "No email is provided by the Steam API"
u.Description = "No description is provided by the Steam API"
if len(player.LocationStateCode) > 0 && len(player.LocationCountryCode) > 0 {
u.Location = fmt.Sprintf("%s, %s", player.LocationStateCode, player.LocationCountryCode)
} else if len(player.LocationCountryCode) > 0 {
u.Location = player.LocationCountryCode
} else if len(player.LocationStateCode) > 0 {
u.Location = player.LocationStateCode
} else {
u.Location = "No location is provided by the Steam API"
}
return u, nil
}