本文整理匯總了Golang中github.com/cheggaaa/pb.ProgressBar.Callback方法的典型用法代碼示例。如果您正苦於以下問題:Golang ProgressBar.Callback方法的具體用法?Golang ProgressBar.Callback怎麽用?Golang ProgressBar.Callback使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cheggaaa/pb.ProgressBar
的用法示例。
在下文中一共展示了ProgressBar.Callback方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: PostMultipartP
// PostMultipartP posts a multipart message in the MIME internet format with a callback function with a string stating the upload Progress.
func (c *Client) PostMultipartP(path string, files map[string][]byte, params Params, out interface{}, callback func(s string)) error {
body := &bytes.Buffer{}
writer := multipart.NewWriter(body)
for name, source := range files {
part, err := writer.CreateFormFile(name, "source.tgz")
if err != nil {
return err
}
_, err = io.Copy(part, bytes.NewReader(source))
if err != nil {
return err
}
}
for name, value := range params {
writer.WriteField(name, value)
}
err := writer.Close()
if err != nil {
return err
}
var bodyReader io.Reader
bodyReader = body
var bar *pb.ProgressBar
if callback != nil {
bar = pb.New(body.Len()).SetUnits(pb.U_BYTES)
bar.NotPrint = true
bar.ShowBar = false
bar.Callback = callback
bar.Start()
bodyReader = bar.NewProxyReader(body)
}
req, err := c.request("POST", path, bodyReader)
if err != nil {
return err
}
req.SetBasicAuth("convox", string(c.Password))
req.Header.Set("Content-Type", writer.FormDataContentType())
res, err := c.client().Do(req)
if err != nil {
return err
}
defer res.Body.Close()
if err := responseError(res); err != nil {
return err
}
data, err := ioutil.ReadAll(res.Body)
if err != nil {
return err
}
if out != nil {
err = json.Unmarshal(data, out)
if err != nil {
return err
}
}
if callback != nil {
bar.Finish()
}
return nil
}