本文整理匯總了Golang中github.com/Terry-Mao/bfs/store/needle.Needle.Cookie方法的典型用法代碼示例。如果您正苦於以下問題:Golang Needle.Cookie方法的具體用法?Golang Needle.Cookie怎麽用?Golang Needle.Cookie使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/Terry-Mao/bfs/store/needle.Needle
的用法示例。
在下文中一共展示了Needle.Cookie方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ServeHTTP
func (h httpGetHandler) ServeHTTP(wr http.ResponseWriter, r *http.Request) {
var (
now = time.Now()
v *Volume
n *needle.Needle
err error
vid, key, cookie int64
ret = http.StatusOK
params = r.URL.Query()
)
if r.Method != "GET" && r.Method != "HEAD" {
ret = http.StatusMethodNotAllowed
http.Error(wr, "method not allowed", ret)
return
}
defer HttpGetWriter(r, wr, now, &err, &ret)
if vid, err = strconv.ParseInt(params.Get("vid"), 10, 32); err != nil {
log.Errorf("strconv.ParseInt(\"%s\") error(%v)", params.Get("vid"), err)
ret = http.StatusBadRequest
return
}
if key, err = strconv.ParseInt(params.Get("key"), 10, 64); err != nil {
log.Errorf("strconv.ParseInt(\"%s\") error(%v)", params.Get("key"), err)
ret = http.StatusBadRequest
return
}
if cookie, err = strconv.ParseInt(params.Get("cookie"), 10, 32); err != nil {
log.Errorf("strconv.ParseInt(\"%s\") error(%v)", params.Get("cookie"), err)
ret = http.StatusBadRequest
return
}
n = h.s.Needle()
n.Key = key
n.Cookie = int32(cookie)
if v = h.s.Volumes[int32(vid)]; v != nil {
if err = v.Get(n); err != nil {
if err == errors.ErrNeedleDeleted || err == errors.ErrNeedleNotExist {
ret = http.StatusNotFound
} else {
ret = http.StatusInternalServerError
}
}
} else {
ret = http.StatusNotFound
err = errors.ErrVolumeNotExist
}
if err == nil {
if r.Method == "GET" {
if _, err = wr.Write(n.Data); err != nil {
log.Errorf("wr.Write() error(%v)", err)
ret = http.StatusInternalServerError
}
}
if log.V(1) {
log.Infof("get a needle: %v", n)
}
}
h.s.FreeNeedle(n)
return
}