本文整理汇总了Golang中strings.Reader.Seek方法的典型用法代码示例。如果您正苦于以下问题:Golang Reader.Seek方法的具体用法?Golang Reader.Seek怎么用?Golang Reader.Seek使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类strings.Reader
的用法示例。
在下文中一共展示了Reader.Seek方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: merchantUploadImageFromStringsReader
func (c *Client) merchantUploadImageFromStringsReader(filename string, reader *strings.Reader) (imageURL string, err error) {
originalOffset, err := reader.Seek(0, 1)
if err != nil {
return
}
FormDataFileName := escapeQuotes(filename)
ContentLength := int64(multipart_constPartLen + len(FormDataFileName) + reader.Len())
hasRetry := false
RETRY:
token, err := c.Token()
if err != nil {
return
}
url_ := merchantUploadImageURL(token, filename)
if hasRetry {
if _, err = reader.Seek(originalOffset, 0); err != nil {
return
}
}
mr := io.MultiReader(
strings.NewReader(multipart_formDataFront),
strings.NewReader(FormDataFileName),
strings.NewReader(multipart_formDataMiddle),
reader,
strings.NewReader(multipart_formDataEnd),
)
httpReq, err := http.NewRequest("POST", url_, mr)
if err != nil {
return
}
httpReq.Header.Set("Content-Type", multipart_ContentType)
httpReq.ContentLength = ContentLength
httpResp, err := c.httpClient.Do(httpReq)
if err != nil {
return
}
defer httpResp.Body.Close()
if httpResp.StatusCode != http.StatusOK {
err = fmt.Errorf("http.Status: %s", httpResp.Status)
return
}
var result struct {
Error
ImageURL string `json:"image_url"`
}
if err = json.NewDecoder(httpResp.Body).Decode(&result); err != nil {
return
}
switch result.ErrCode {
case errCodeOK:
imageURL = result.ImageURL
return
case errCodeTimeout:
if !hasRetry {
hasRetry = true
timeoutRetryWait()
goto RETRY
}
fallthrough
default:
err = &result.Error
return
}
}