当前位置: 首页>>代码示例>>Golang>>正文


Golang Volume.Get方法代码示例

本文整理汇总了Golang中github.com/Terry-Mao/bfs/store/volume.Volume.Get方法的典型用法代码示例。如果您正苦于以下问题:Golang Volume.Get方法的具体用法?Golang Volume.Get怎么用?Golang Volume.Get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/Terry-Mao/bfs/store/volume.Volume的用法示例。


在下文中一共展示了Volume.Get方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: ServeHTTP

func (h httpGetHandler) ServeHTTP(wr http.ResponseWriter, r *http.Request) {
	var (
		v                *volume.Volume
		n                *needle.Needle
		err              error
		vid, key, cookie int64
		ret              = http.StatusOK
		params           = r.URL.Query()
		now              = time.Now()
	)
	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
}
开发者ID:wareseeker,项目名称:bfs,代码行数:60,代码来源:http_api.go

示例2: TestStore

func TestStore(t *testing.T) {
	var (
		s       *Store
		z       *Zookeeper
		v       *volume.Volume
		err     error
		data    = []byte("test")
		n       = &needle.Needle{}
		bfile   = "./test/_free_block_1"
		ifile   = "./test/_free_block_1.idx"
		vbfile  = "./test/1_0"
		vifile  = "./test/1_0.idx"
		b2file  = "./test/_free_block_2"
		i2file  = "./test/_free_block_2.idx"
		vb2file = "./test/2_0"
		vi2file = "./test/2_0.idx"
	)
	os.Remove(testConf.VolumeIndex)
	os.Remove(testConf.FreeVolumeIndex)
	os.Remove(bfile)
	os.Remove(ifile)
	os.Remove(b2file)
	os.Remove(i2file)
	os.Remove(vbfile)
	os.Remove(vifile)
	os.Remove(vb2file)
	os.Remove(vi2file)
	os.Remove("./test/1_1")
	os.Remove("./test/1_1.idx")
	os.Remove("./test/1_2")
	os.Remove("./test/1_2.idx")
	defer os.Remove(testConf.VolumeIndex)
	defer os.Remove(testConf.FreeVolumeIndex)
	defer os.Remove(bfile)
	defer os.Remove(ifile)
	defer os.Remove(b2file)
	defer os.Remove(i2file)
	defer os.Remove(vbfile)
	defer os.Remove(vifile)
	defer os.Remove(vb2file)
	defer os.Remove(vi2file)
	defer os.Remove("./test/1_1")
	defer os.Remove("./test/1_1.idx")
	defer os.Remove("./test/1_2")
	defer os.Remove("./test/1_2.idx")
	if z, err = NewZookeeper([]string{"localhost:2181"}, time.Second*1, "/rack", "", "test"); err != nil {
		t.Errorf("NewZookeeper() error(%v)", err)
		t.FailNow()
	}
	z.DelVolume(1)
	z.DelVolume(2)
	if s, err = NewStore(z, testConf); err != nil {
		t.Errorf("NewStore() error(%v)", err)
		t.FailNow()
	}
	defer s.Close()
	if _, err = s.AddFreeVolume(2, "./test", "./test"); err != nil {
		t.Errorf("s.AddFreeVolume() error(%v)", err)
		t.FailNow()
	}
	if v, err = s.AddVolume(1); err != nil {
		t.Errorf("AddVolume() error(%v)", err)
		t.FailNow()
	}
	if v = s.Volumes[1]; v == nil {
		t.Error("Volume(1) not exist")
		t.FailNow()
	}
	n.Buffer = make([]byte, testConf.NeedleMaxSize)
	n.Init(1, 1, data)
	n.Write()
	if err = v.Add(n); err != nil {
		t.Errorf("v.Add(1) error(%v)", err)
		t.FailNow()
	}
	n.Key = 1
	n.Cookie = 1
	if err = v.Get(n); err != nil {
		t.Errorf("v.Get(1) error(%v)", err)
		t.FailNow()
	}
	if err = s.BulkVolume(2, b2file, i2file); err != nil {
		t.Errorf("Bulk(1) error(%v)", err)
		t.FailNow()
	}
	if v = s.Volumes[2]; v == nil {
		t.Error("Volume(2) not exist")
		t.FailNow()
	}
	if err = v.Add(n); err != nil {
		t.Errorf("v.Add() error(%v)", err)
		t.FailNow()
	}
	n.Key = 1
	n.Cookie = 1
	if err = v.Get(n); err != nil {
		t.Errorf("v.Get(1) error(%v)", err)
		t.FailNow()
	}
	if err = s.CompactVolume(1); err != nil {
//.........这里部分代码省略.........
开发者ID:wareseeker,项目名称:bfs,代码行数:101,代码来源:store_test.go


注:本文中的github.com/Terry-Mao/bfs/store/volume.Volume.Get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。