本文整理汇总了Golang中github.com/JanBerktold/rbxweb.Client.I32toa方法的典型用法代码示例。如果您正苦于以下问题:Golang Client.I32toa方法的具体用法?Golang Client.I32toa怎么用?Golang Client.I32toa使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/JanBerktold/rbxweb.Client
的用法示例。
在下文中一共展示了Client.I32toa方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: GetLatestModel
// GetLatestModel returns the asset id of the latest model for a given user.
// While this is useful for retrieving the asset id of a newly created model
// that was just uploaded, it is not necessarily reliable for this purpose.
func GetLatestModel(client *rbxweb.Client, userId int32) (assetId int64, err error) {
if userId == 0 {
return 0, errors.New("invalid user id")
}
query := url.Values{
"Category": {"Models"},
"SortType": {"RecentlyUpdated"},
"IncludeNotForSale": {"true"},
"ResultsPerPage": {"1"},
"CreatorID": {client.I32toa(userId)},
}
resp, err := client.Get(client.GetURL(`api`, `/catalog/json`, query))
if err = client.AssertResp(resp, err); err != nil {
return 0, err
}
defer resp.Body.Close()
dec := json.NewDecoder(resp.Body)
var asset []struct {
AssetId int64
}
if err = dec.Decode(&asset); err != nil {
return 0, errors.New("JSON decode failed: " + err.Error())
}
return asset[0].AssetId, nil
}
示例2: GetNameFromId
// GetNameFromId returns a user name from a user id.
func GetNameFromId(client *rbxweb.Client, id int32) (name string, err error) {
if id == 0 {
return "", errors.New("id not specified")
}
resp, err := client.Get(client.GetURL(`api`, `/users/`+client.I32toa(id), nil))
if err = client.AssertResp(resp, err); err != nil {
return "", err
}
defer resp.Body.Close()
dec := json.NewDecoder(resp.Body)
var user struct {
Username string
}
if err = dec.Decode(&user); err != nil {
return "", errors.New("JSON decode failed: " + err.Error())
}
return user.Username, nil
}