本文整理匯總了Golang中github.com/Terry-Mao/bfs/store/volume.Volume.Write方法的典型用法代碼示例。如果您正苦於以下問題:Golang Volume.Write方法的具體用法?Golang Volume.Write怎麽用?Golang Volume.Write使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/Terry-Mao/bfs/store/volume.Volume
的用法示例。
在下文中一共展示了Volume.Write方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ServeHTTP
func (h httpUploadsHandler) ServeHTTP(wr http.ResponseWriter, r *http.Request) {
var (
i, nn int
err error
vid int64
key int64
cookie int64
size int64
str string
keys []string
cookies []string
v *volume.Volume
ns *needle.Needles
file multipart.File
fh *multipart.FileHeader
fhs []*multipart.FileHeader
res = map[string]interface{}{}
)
if r.Method != "POST" {
http.Error(wr, "method not allowed", http.StatusMethodNotAllowed)
return
}
defer HttpPostWriter(r, wr, time.Now(), &err, res)
// check total content-length
if size, err = strconv.ParseInt(r.Header.Get("Content-Length"), 10, 64); err != nil {
err = errors.ErrInternal
return
}
if size > int64(h.c.NeedleMaxSize*h.c.BatchMaxNum) {
err = errors.ErrInternal
return
}
str = r.FormValue("vid")
if vid, err = strconv.ParseInt(str, 10, 32); err != nil {
log.Errorf("strconv.ParseInt(\"%s\") error(%v)", str, err)
err = errors.ErrParam
return
}
keys = r.MultipartForm.Value["keys"]
cookies = r.MultipartForm.Value["cookies"]
if len(keys) != len(cookies) {
log.Errorf("param length not match, keys: %d, cookies: %d", len(keys), len(cookies))
err = errors.ErrParam
return
}
fhs = r.MultipartForm.File["file"]
nn = len(fhs)
if len(keys) != nn {
log.Errorf("param length not match, keys: %d, cookies: %d, files: %d", len(keys), len(cookies), len(fhs))
err = errors.ErrParam
return
}
ns = h.s.Needles(nn)
for i, fh = range fhs {
if key, err = strconv.ParseInt(keys[i], 10, 64); err != nil {
log.Errorf("strconv.ParseInt(\"%s\") error(%v)", keys[i], err)
err = errors.ErrParam
break
}
if cookie, err = strconv.ParseInt(cookies[i], 10, 32); err != nil {
log.Errorf("strconv.ParseInt(\"%s\") error(%v)", cookies[i], err)
err = errors.ErrParam
break
}
if file, err = fh.Open(); err != nil {
log.Errorf("fh.Open() error(%v)", err)
break
}
defer file.Close()
// check size
if size, err = fileSize(file); err != nil {
break
}
if size > int64(h.c.NeedleMaxSize) {
err = errors.ErrNeedleTooLarge
break
}
if err = ns.WriteFrom(key, int32(cookie), int32(size), file); err != nil {
break
}
}
if err == nil {
if v = h.s.Volumes[int32(vid)]; v != nil {
err = v.Write(ns)
} else {
err = errors.ErrVolumeNotExist
}
}
h.s.FreeNeedles(nn, ns)
return
}