本文整理汇总了Golang中github.com/Terry-Mao/bfs/store/needle.Needle.InitSize方法的典型用法代码示例。如果您正苦于以下问题:Golang Needle.InitSize方法的具体用法?Golang Needle.InitSize怎么用?Golang Needle.InitSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/Terry-Mao/bfs/store/needle.Needle
的用法示例。
在下文中一共展示了Needle.InitSize方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ServeHTTP
func (h httpUploadsHandler) ServeHTTP(wr http.ResponseWriter, r *http.Request) {
var (
i, nn int
ok bool
err error
vid int64
key int64
cookie int64
size int64
str string
keys []string
cookies []string
sr sizer
fr *os.File
fi os.FileInfo
v *Volume
n *needle.Needle
ns *needle.Needles
uerr errors.Error
file multipart.File
fh *multipart.FileHeader
fhs []*multipart.FileHeader
res = map[string]interface{}{"ret": errors.RetOK}
)
if r.Method != "POST" {
http.Error(wr, "method not allowed", http.StatusMethodNotAllowed)
return
}
defer HttpPostWriter(r, wr, time.Now(), res)
// check total content-length
if size, err = strconv.ParseInt(r.Header.Get("Content-Length"), 10, 64); err != nil {
res["ret"] = errors.RetInternalErr
return
}
if size > int64(h.c.NeedleMaxSize*h.c.BatchMaxNum) {
res["ret"] = errors.RetNeedleTooLarge
return
}
str = r.FormValue("vid")
if vid, err = strconv.ParseInt(str, 10, 32); err != nil {
log.Errorf("strconv.ParseInt(\"%s\") error(%v)", str, err)
res["ret"] = errors.RetParamErr
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))
res["ret"] = errors.RetParamErr
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))
res["ret"] = errors.RetParamErr
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
}
// check size
if sr, ok = file.(sizer); ok {
size = sr.Size()
} else if fr, ok = file.(*os.File); ok {
if fi, err = fr.Stat(); err != nil {
goto failed
}
size = fi.Size()
}
if size > int64(h.c.NeedleMaxSize) {
err = errors.ErrNeedleTooLarge
goto failed
}
n = &ns.Items[i]
n.InitSize(key, int32(cookie), int32(size))
if err = ns.WriteFrom(n, file); err != nil {
goto failed
}
continue
failed:
file.Close()
break
}
if err == nil {
if v = h.s.Volumes[int32(vid)]; v != nil {
err = v.Write(ns)
//.........这里部分代码省略.........