当前位置: 首页>>代码示例>>Golang>>正文


Golang Client.Atoi64方法代码示例

本文整理汇总了Golang中github.com/JanBerktold/rbxweb.Client.Atoi64方法的典型用法代码示例。如果您正苦于以下问题:Golang Client.Atoi64方法的具体用法?Golang Client.Atoi64怎么用?Golang Client.Atoi64使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/JanBerktold/rbxweb.Client的用法示例。


在下文中一共展示了Client.Atoi64方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Upload

// Upload generically uploads data from `reader` as an asset to the ROBLOX
// website. `info` can be used to specify information about the model. The
// following parameters are known:
//
//     type           - The type of asset.
//     assetid        - The id of the asset to update. 0 uploads a new asset.
//     name           - The name of the asset.
//     description    - The asset's description.
//     genreTypeId    - The asset's genre.
//     isPublic       - Whether the asset can be taken by other users.
//     allowComments  - Whether users can comment on the asset.
//
// The success of this function is highly dependent on these parameters. For
// example, most asset types may only be uploaded by authorized users.
// Parameters that specify information about the asset only apply for new
// assets. That is, updating an asset will only update the contents, but not
// the information about it.
//
// `assetVersionId` is the version id of the uploaded asset. This is unique
// for each upload. This can be used with GetIdFromVersion to get the asset
// id.
//
// This function requires the client to be logged in.
func Upload(client *rbxweb.Client, reader io.Reader, info url.Values) (assetVersionId int64, err error) {
	buf := new(bytes.Buffer)
	buf.ReadFrom(reader)
	req, _ := http.NewRequest("POST", client.GetURL(`www`, `/Data/Upload.ashx`, info), buf)
	req.Header.Set("User-Agent", "roblox/rbxweb")

	resp, err := client.Do(req)
	if err = client.AssertResp(resp, err); err != nil {
		return 0, err
	}
	defer resp.Body.Close()

	r := new(bytes.Buffer)
	r.ReadFrom(resp.Body)
	assetVersionId, _ = client.Atoi64(r.String())

	return assetVersionId, err
}
开发者ID:JanBerktold,项目名称:rbxweb,代码行数:41,代码来源:asset.go

示例2: GetIdFromVersion

// GetIdFromVersion returns an asset id from an asset version id.
func GetIdFromVersion(client *rbxweb.Client, assetVersionId int64) (assetId int64, err error) {
	query := url.Values{
		"avid": {client.I64toa(assetVersionId)},
	}

	// This relies on how asset names are converted to url names. Currently,
	// if an asset name is "_", its url becomes "unnamed".
	req, _ := http.NewRequest("HEAD", client.GetURL(`www`, `/_-item`, query), nil)
	resp, err := client.Do(req)
	if err = client.AssertResp(resp, err); err != nil {
		return 0, err
	}
	resp.Body.Close()

	if err = client.AssertResp(resp, err); err != nil {
		return 0, err
	}

	return client.Atoi64(resp.Request.URL.Query().Get("id"))
}
开发者ID:JanBerktold,项目名称:rbxweb,代码行数:21,代码来源:asset.go


注:本文中的github.com/JanBerktold/rbxweb.Client.Atoi64方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。