• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang types.ObjectID类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/ironsmile/nedomi/types.ObjectID的典型用法代码示例。如果您正苦于以下问题:Golang ObjectID类的具体用法?Golang ObjectID怎么用?Golang ObjectID使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: getObjectIDPath

func (s *Disk) getObjectIDPath(id *types.ObjectID) string {
	// !TODO redo this with more []byte appending(we know how big it will be)
	// less string concatination
	h := id.StrHash()
	// Disk objects are writen 2 levels deep with maximum of 256 folders in each
	if s.skipCacheKeyInPath {
		return filepath.Join(s.path, h[0:2], h[2:4], h)
	}

	return filepath.Join(s.path, id.CacheKey(), h[0:2], h[2:4], h)
}
开发者ID:gowebabc,项目名称:nedomi,代码行数:11,代码来源:utils.go


示例2: GetAvailableParts

// GetAvailableParts returns an io.ReadCloser that will read the specified part of the object.
func (s *Storage) GetAvailableParts(oid *types.ObjectID) ([]*types.ObjectIndex, error) {
	var result = make([]*types.ObjectIndex, 0, len(s.Parts))
	if obj, ok := s.Parts[oid.Hash()]; ok {
		for partNum := range obj {
			result = append(result,
				&types.ObjectIndex{
					ObjID: oid,
					Part:  partNum,
				})
		}
	}
	return result, os.ErrNotExist
}
开发者ID:na--,项目名称:nedomi,代码行数:14,代码来源:storage.go


示例3: TestStorageHeadersFunctionWithManyGoroutines

// Tests the storage headers map in multithreading usage. An error will be
// triggered by a race condition. This may or may not happen. So no failures
// in the test do not mean there are no problems. But it may catch an error
// from time to time. In fact it does quite often for me.
//
// Most of the time the test fails with a panic. And most of the time
// the panic is in the runtime. So isntead of a error message via t.Error
// the test fails with a panic.
func TestStorageHeadersFunctionWithManyGoroutines(t *testing.T) {
	up, cz, ca, goroutines := setup()

	pathFunc := func(i int) string {
		return fmt.Sprintf("/%d", i)
	}

	headerKeyFunc := func(i int) string {
		return fmt.Sprintf("X-Header-%d", i)
	}

	headerValueFunc := func(i int) string {
		return fmt.Sprintf("value-%d", i)
	}

	// setup the response
	for i := 0; i < 100; i++ {
		var headers = make(http.Header)
		headers.Add(headerKeyFunc(i), headerValueFunc(i))
		up.addFakeResponse(pathFunc(i),
			fakeResponse{
				Status:       "200",
				ResponseTime: 10 * time.Nanosecond,
				Headers:      headers,
			},
		)
	}
	storage := New(cz, ca, newStdLogger())
	defer storage.Close()
	defer os.RemoveAll(storage.path)
	ctx := contexts.NewVhostContext(context.Background(), &types.VirtualHost{Upstream: up})

	concurrentTestHelper(t, goroutines, 100, func(t *testing.T, i, j int) {
		oid := types.ObjectID{}
		oid.CacheKey = "1"
		oid.Path = pathFunc(i)

		header, err := storage.Headers(ctx, oid)
		if err != nil {
			t.Errorf("Got error from storage.Headers on %d, %d: %s", j, i, err)
		}
		value := header.Get(headerKeyFunc(i))
		if value != headerValueFunc(i) {
			t.Errorf("Expected header [%s] to have value [%s] but it had value %s for %d, %d", headerKeyFunc(i), headerValueFunc(i), value, j, i)
		}
	})

}
开发者ID:gitter-badger,项目名称:nedomi,代码行数:56,代码来源:impl_test.go


示例4: TestDiskCloseReturnesAfterFinishingRequests

func TestDiskCloseReturnesAfterFinishingRequests(t *testing.T) {
	expected := "awesome"
	fakeup, cz, ca, _ := setup()
	runtime.GOMAXPROCS(runtime.NumCPU())
	up := newBlockingUpstream(fakeup)
	up.addFakeResponse("/path",
		fakeResponse{
			Status:       "200",
			ResponseTime: 0,
			Response:     expected,
		})

	storage := New(cz, ca, newStdLogger())
	defer os.RemoveAll(storage.path)

	ctx := contexts.NewVhostContext(context.Background(), &types.VirtualHost{Upstream: up})
	wCh := make(chan struct{})
	go func(ch chan struct{}) {
		defer close(ch)
		oid := types.ObjectID{}
		oid.CacheKey = "1"
		oid.Path = "/path"
		resp, err := storage.GetFullFile(ctx, oid)
		if err != nil {
			t.Errorf("Got Error on a GetFullFile on closing storage:\n%s", err)
		}
		b, err := ioutil.ReadAll(resp)
		if err != nil {
			t.Errorf("Got Error on a ReadAll on an already closed storage:\n%s", err)
		}
		if string(b) != expected {
			t.Errorf("Expected read from GetFullFile was %s but got %s", expected, string(b))
		}

	}(wCh)
	go close(<-up.requestPartial)
	err := storage.Close()
	if err != nil {
		t.Errorf("Storage.Close() shouldn't have returned error\n%s", err)
	}
	<-wCh
}
开发者ID:gitter-badger,项目名称:nedomi,代码行数:42,代码来源:close_test.go


示例5: TestStorageSimultaneousGets

func TestStorageSimultaneousGets(t *testing.T) {
	fakeup, cz, ca, goroutines := setup()
	runtime.GOMAXPROCS(runtime.NumCPU())
	up := &countingUpstream{
		fakeUpstream: fakeup,
	}

	up.addFakeResponse("/path",
		fakeResponse{
			Status:       "200",
			ResponseTime: 10 * time.Millisecond,
			Response:     "awesome",
		})

	storage := New(cz, ca, newStdLogger())
	defer storage.Close()
	defer os.RemoveAll(storage.path)
	ctx := contexts.NewVhostContext(context.Background(), &types.VirtualHost{Upstream: up})

	concurrentTestHelper(t, goroutines, 1, func(t *testing.T, i, j int) {
		oid := types.ObjectID{}
		oid.CacheKey = "1"
		oid.Path = "/path"
		file, err := storage.GetFullFile(ctx, oid)
		if err != nil {
			t.Errorf("Got error from storage.Get on %d, %d: %s", j, i, err)
		}
		b, err := ioutil.ReadAll(file)
		if err != nil {
			t.Errorf("Got error while reading response on %d, %d: %s", j, i, err)
		}
		if string(b) != "awesome" {
			t.Errorf("The response was expected to be 'awesome' but it was %s", string(b))
		}

	})

	if up.called != 1 {
		t.Errorf("Expected upstream.GetRequest to be called once it got called %d", up.called)
	}
}
开发者ID:gitter-badger,项目名称:nedomi,代码行数:41,代码来源:impl_test.go


示例6: TestDiskCloseReturnesAfterFinishingHeaders

func TestDiskCloseReturnesAfterFinishingHeaders(t *testing.T) {
	var expected = make(http.Header)
	var expectedHeader, expectedValue = "awesome-header", "awesome-value"
	expected.Add(expectedHeader, expectedValue)
	fakeup, cz, ca, _ := setup()
	runtime.GOMAXPROCS(runtime.NumCPU())
	up := newBlockingUpstream(fakeup)
	up.addFakeResponse("/path",
		fakeResponse{
			Status:       "200",
			ResponseTime: 0,
			Headers:      expected,
		})

	storage := New(cz, ca, newStdLogger())
	defer os.RemoveAll(storage.path)

	ctx := contexts.NewVhostContext(context.Background(), &types.VirtualHost{Upstream: up})
	wCh := make(chan struct{})
	go func(ch chan struct{}) {
		defer close(ch)
		oid := types.ObjectID{}
		oid.CacheKey = "1"
		oid.Path = "/path"

		headers, err := storage.Headers(ctx, oid)
		if err != nil {
			t.Errorf("Got Error on a Headers on closing storage:\n%s", err)
		}
		if headers.Get(expectedHeader) != expectedValue { //!TODO: better check
			t.Errorf("The returned headers:\n%s\n Did not match the expected headers\n%s", headers, expected)
		}

	}(wCh)
	go close(<-up.requestHeader)
	err := storage.Close()
	if err != nil {
		t.Errorf("Storage.Close() shouldn't have returned error\n%s", err)
	}
	<-wCh
}
开发者ID:gitter-badger,项目名称:nedomi,代码行数:41,代码来源:close_test.go


示例7: Discard

// Discard removes the object and its metadata.
func (s *Storage) Discard(id *types.ObjectID) error {
	if _, ok := s.Objects[id.Hash()]; !ok {
		return os.ErrNotExist
	}
	delete(s.Objects, id.Hash())
	delete(s.Parts, id.Hash())

	return nil
}
开发者ID:na--,项目名称:nedomi,代码行数:10,代码来源:storage.go


示例8: getObjectIDPath

func (s *Disk) getObjectIDPath(id *types.ObjectID) string {
	h := id.StrHash()
	// Disk objects are writen 2 levels deep with maximum of 256 folders in each
	return filepath.Join(s.path, id.CacheKey(), h[0:2], h[2:4], h)
}
开发者ID:na--,项目名称:nedomi,代码行数:5,代码来源:utils.go


示例9: GetMetadata

// GetMetadata returns the metadata for this object, if present.
func (s *Storage) GetMetadata(id *types.ObjectID) (*types.ObjectMetadata, error) {
	if obj, ok := s.Objects[id.Hash()]; ok {
		return obj, nil
	}
	return nil, os.ErrNotExist
}
开发者ID:na--,项目名称:nedomi,代码行数:7,代码来源:storage.go



注:本文中的github.com/ironsmile/nedomi/types.ObjectID类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang assert.New函数代码示例发布时间:2022-05-23
下一篇:
Golang types.NewObjectID函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap