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

Golang model.New函数代码示例

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

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



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

示例1: Run

func (c *GitDivertFinishCmd) Run(args ...string) (err error) {
	mod, err := model.New(c.WD, true, c.ChunkSize, c.PoolSize)
	if err != nil {
		return
	}

	divert := git.NewDivert(mod.Git)
	isInProgress, err := divert.IsInProgress()
	if err != nil {
		return
	}
	if !isInProgress {
		err = fmt.Errorf("diversion is not in progress")
	}

	spec, err := divert.ReadSpec()
	if err != nil {
		return
	}
	if err = divert.Commit(spec, c.Message); err != nil {
		return
	}

	err = divert.Cleanup(spec)

	return
}
开发者ID:pombredanne,项目名称:bar,代码行数:27,代码来源:git-divert-finish.go


示例2: Run

func (c *GitDivertBeginCmd) Run(args ...string) (err error) {
	logx.Debugf("beginning covert op %s", args)

	if len(args) == 0 {
		err = fmt.Errorf("no branch")
		return
	}

	branch := args[0]
	names := args[1:]

	mod, err := model.New(c.WD, true, c.ChunkSize, c.PoolSize)
	if err != nil {
		return
	}
	divert := git.NewDivert(mod.Git)
	var spec git.DivertSpec
	if spec, err = divert.PrepareBegin(branch, names...); err != nil {
		return
	}

	if err = divert.Begin(spec); err == nil {
		return
	}

	return
}
开发者ID:pombredanne,项目名称:bar,代码行数:27,代码来源:git-divert-begin.go


示例3: Test_Assembler_StoreChunk

func Test_Assembler_StoreChunk(t *testing.T) {
	wd, _ := os.Getwd()
	wd = filepath.Join(wd, "testdata", "assembler-StoreChunk")
	m, err := model.New(wd, false, proto.CHUNK_SIZE, 128)
	assert.NoError(t, err)

	data := []byte("mama myla ramu")
	hasher := sha3.New256()
	_, err = hasher.Write([]byte(data))
	id := proto.ID(hex.EncodeToString(hasher.Sum(nil)))

	a, err := model.NewAssembler(m)
	assert.NoError(t, err)
	defer a.Close()

	err = a.StoreChunk(bytes.NewReader(data), id)
	assert.NoError(t, err)

	// check stored chunk
	f, err := os.Open(filepath.Join(a.Where, id.String()))
	assert.NoError(t, err)
	defer f.Close()
	defer os.Remove(filepath.Join(a.Where, id.String()))

	r2, err := ioutil.ReadAll(f)
	assert.NoError(t, err)

	assert.Equal(t, data, r2)
}
开发者ID:pombredanne,项目名称:bar,代码行数:29,代码来源:assembler_test.go


示例4: Run

func (c *PingCmd) Run(args ...string) (err error) {
	var mod *model.Model
	if mod, err = model.New(c.WD, false, c.ChunkSize, c.PoolSize); err != nil {
		return
	}
	trans := transport.NewTransport(mod, "", c.Endpoint, c.PoolSize)
	res, err := trans.ServerInfo()
	logx.Info(res)
	return
}
开发者ID:pombredanne,项目名称:bar,代码行数:10,代码来源:ping.go


示例5: Test_Model_IsBlobs

func Test_Model_IsBlobs(t *testing.T) {
	tree := fixtures.NewTree("is-blob", "")
	assert.NoError(t, tree.Populate())
	defer tree.Squash()

	names := lists.NewFileList().ListDir(tree.CWD)

	m, err := model.New(tree.CWD, false, 1024*1024, 16)
	assert.NoError(t, err)

	_, err = m.IsBlobs(names...)
	assert.NoError(t, err)
}
开发者ID:pombredanne,项目名称:bar,代码行数:13,代码来源:mode_test.go


示例6: Test_Model_FeedManifests_Nil

func Test_Model_FeedManifests_Nil(t *testing.T) {
	tree := fixtures.NewTree("feed-manifests", "")
	assert.NoError(t, tree.Populate())
	defer tree.Squash()

	names := lists.NewFileList().ListDir(tree.CWD)
	tree.KillBLOB("file-one.bin")

	m, err := model.New(tree.CWD, false, 1024*1024, 16)
	assert.NoError(t, err)
	lx, err := m.FeedManifests(true, true, false, names...)
	assert.Error(t, err)
	assert.Len(t, lx.Names(), 15)
}
开发者ID:pombredanne,项目名称:bar,代码行数:14,代码来源:model_feed_test.go


示例7: Test_Transport_ServerInfo

func Test_Transport_ServerInfo(t *testing.T) {
	root := "testdata-Ping"

	srv, err := fixtures.NewFixtureServer(root)
	assert.NoError(t, err)
	defer srv.Stop()
	mod, err := model.New("", false, proto.CHUNK_SIZE, 16)
	assert.NoError(t, err)
	tr := transport.NewTransport(mod, srv.HTTPEndpoint, srv.RPCEndpoints[0], 16)
	defer tr.Close()

	res, err := tr.ServerInfo()
	assert.NoError(t, err)
	assert.Equal(t, int64(1024*1024*2), res.ChunkSize)
}
开发者ID:pombredanne,项目名称:bar,代码行数:15,代码来源:transport_test.go


示例8: Run

func (c *UpCmd) Run(args ...string) (err error) {
	var mod *model.Model

	if mod, err = model.New(c.WD, c.UseGit, c.ChunkSize, c.PoolSize); err != nil {
		return
	}

	feed := lists.NewFileList(args...).ListDir(c.WD)

	isDirty, dirty, err := mod.Check(feed...)
	if err != nil {
		return
	}
	if isDirty {
		err = fmt.Errorf("dirty files in working tree %s", dirty)
		return
	}

	if c.UseGit {
		// filter by attrs
		feed, err = mod.Git.FilterByAttr("bar", feed...)
	}

	blobs, err := mod.FeedManifests(true, false, true, feed...)
	if err != nil {
		return
	}

	logx.Debugf("collected blobs %s", blobs.IDMap())

	trans := transport.NewTransport(mod, "", c.Endpoint, c.PoolSize)

	err = trans.Upload(blobs)
	if err != nil {
		return
	}

	if c.Squash {
		if err = mod.SquashBlobs(blobs); err != nil {
			return
		}
		if c.UseGit {
			err = mod.Git.UpdateIndex(blobs.Names()...)
		}
	}

	return
}
开发者ID:pombredanne,项目名称:bar,代码行数:48,代码来源:up.go


示例9: Run

func (c *GitDivertPushCmd) Run(args ...string) (err error) {
	mod, err := model.New(c.WD, true, c.ChunkSize, c.PoolSize)
	if err != nil {
		return
	}

	var upstream, branch string
	if len(args) == 0 {
		err = fmt.Errorf("no upstream and/or branch provided")
		return
	}
	if len(args) == 1 {
		upstream = "origin"
		branch = args[0]
	} else {
		upstream = args[0]
		branch = args[1]
	}

	// checks
	current, branches, err := mod.Git.GetBranches()
	if err != nil {
		return
	}
	if branch == current {
		err = fmt.Errorf("cannot push current branch. use `git push ...`")
		return
	}
	var exists bool
	for _, i := range branches {
		if branch == i {
			exists = true
			break
		}
	}
	if !exists {
		err = fmt.Errorf("branch %s is not exists")
		return
	}

	if err = mod.Git.Push(upstream, branch); err != nil {
		return
	}
	logx.Debugf("%s/%s pushed", upstream, branch)
	return
}
开发者ID:pombredanne,项目名称:bar,代码行数:46,代码来源:git-divert-push.go


示例10: Test_Assembler_Assemble

func Test_Assembler_Assemble(t *testing.T) {
	tree := fixtures.NewTree("Assembler", "")
	assert.NoError(t, tree.Populate())
	defer tree.Squash()

	ml, err := model.New(tree.CWD, false, proto.CHUNK_SIZE, 16)
	assert.NoError(t, err)

	names := []string{
		"file-two.bin", "one/file-two.bin", "one/file-three.bin",
	}

	// get manifests
	mx, err := ml.FeedManifests(true, true, true,
		lists.NewFileList(names...).ListDir(tree.CWD)...)
	assert.NoError(t, err)

	a, err := model.NewAssembler(ml)
	assert.NoError(t, err)

	for name, man := range mx {
		f, err := os.Open(filepath.Join(tree.CWD, name))
		assert.NoError(t, err)
		for _, chunk := range man.Chunks {
			buf := make([]byte, chunk.Size)
			_, err = f.Read(buf)
			assert.NoError(t, err)

			err = a.StoreChunk(bytes.NewReader(buf), chunk.ID)
			assert.NoError(t, err)
		}
	}

	// Kill some blobs
	tree.KillBLOB("file-two.bin")
	tree.KillBLOB("one/file-two.bin")

	err = a.Done(mx)
	assert.NoError(t, err)

	mx1, err := ml.FeedManifests(true, true, true,
		lists.NewFileList(names...).ListDir(tree.CWD)...)
	assert.NoError(t, err)

	assert.Equal(t, mx, mx1)
}
开发者ID:pombredanne,项目名称:bar,代码行数:46,代码来源:assembler_test.go


示例11: Run

func (c *GitCleanCmd) Run(args ...string) (err error) {
	mod, err := model.New(c.WD, true, c.ChunkSize, c.PoolSize)

	var name string
	if len(args) > 0 {
		name = args[0]
	}

	// check divert
	divert := git.NewDivert(mod.Git)
	isInProgress, err := divert.IsInProgress()
	if err != nil {
		return
	}
	if isInProgress {
		var spec git.DivertSpec
		if spec, err = divert.ReadSpec(); err != nil {
			return
		}
		var exists bool
		for _, n := range spec.TargetFiles {
			if n == name {
				exists = true
				break
			}
		}
		if !exists {
			err = fmt.Errorf("wan't clean non-target file %s while divert in progress", name)
			return
		}
	}

	s, err := mod.GetManifest(name, c.Stdin)
	if err != nil {
		return
	}

	logx.Debugf("%s %s", name, s.ID)

	if c.Id {
		fmt.Fprintf(c.Stdout, "%s", s.ID)
	} else {
		err = s.Serialize(c.Stdout)
	}
	return
}
开发者ID:pombredanne,项目名称:bar,代码行数:46,代码来源:git-clean.go


示例12: Run

func (c *GitPreCommitCmd) Run(args ...string) (err error) {
	var filenames []string
	var mod *model.Model
	if mod, err = model.New(c.WD, true, c.ChunkSize, c.PoolSize); err != nil {
		return
	}

	// In divert we need restrict check by target filenames
	divert := git.NewDivert(mod.Git)
	isInDivert, err := divert.IsInProgress()
	if err != nil {
		return
	}
	if isInDivert {
		var spec git.DivertSpec
		if spec, err = divert.ReadSpec(); err != nil {
			return
		}
		filenames = spec.TargetFiles
	}

	isDirty, dirty, err := mod.Check(filenames...)
	if err != nil {
		return
	}
	if isDirty {
		err = fmt.Errorf("dirty files in working tree %s", dirty)
		return
	}

	feedR, err := mod.Git.Diff(filenames...)
	if err != nil {
		return
	}

	blobs, err := mod.Git.ManifestsFromDiff(feedR)
	if err != nil {
		return
	}

	trans := transport.NewTransport(mod, "", c.Endpoint, c.PoolSize)
	err = trans.Upload(blobs)

	return
}
开发者ID:pombredanne,项目名称:bar,代码行数:45,代码来源:git-pre-commit.go


示例13: seed

func seed(t *testing.T, root string) (halt func(), tree *fixtures.Tree, ml *model.Model, srv *fixtures.FixtureServer, trans *transport.Transport) {
	tree = fixtures.NewTree(root, "")
	assert.NoError(t, tree.Populate())

	ml, err := model.New(tree.CWD, false, proto.CHUNK_SIZE, 32)
	assert.NoError(t, err)

	srv, err = fixtures.NewFixtureServer(root)
	assert.NoError(t, err)
	trans = transport.NewTransport(ml, srv.HTTPEndpoint, srv.RPCEndpoints[0], 16)

	halt = func() {
		trans.Close()
		srv.Stop()
		tree.Squash()
	}
	return
}
开发者ID:pombredanne,项目名称:bar,代码行数:18,代码来源:transport_test.go


示例14: Test_Model_FeedManifests_Many

func Test_Model_FeedManifests_Many(t *testing.T) {
	if testing.Short() {
		t.Skip()
	}
	tree := fixtures.NewTree("collect-manifests-large", "")
	defer tree.Squash()

	assert.NoError(t, tree.Populate())
	assert.NoError(t, tree.PopulateN(10, 300))

	names := lists.NewFileList().ListDir(tree.CWD)

	m, err := model.New(tree.CWD, false, 1024*1024, 16)
	assert.NoError(t, err)
	lx, err := m.FeedManifests(true, true, true, names...)
	assert.NoError(t, err)

	assert.Len(t, lx.Names(), 316)
}
开发者ID:pombredanne,项目名称:bar,代码行数:19,代码来源:model_feed_test.go


示例15: Run

func (c *GitInstallCmd) Run(args ...string) (err error) {
	var mod *model.Model
	if mod, err = model.New(c.WD, true, c.ChunkSize, c.PoolSize); err != nil {
		return
	}
	defer mod.Close()

	trans := transport.NewTransport(mod, "", c.Endpoint, c.PoolSize)
	defer trans.Close()

	info, err := trans.ServerInfo()
	if err != nil {
		return
	}

	config := git.NewConfig(info, mod.Git)
	err = config.Install(c.Log)

	return
}
开发者ID:pombredanne,项目名称:bar,代码行数:20,代码来源:git-install.go


示例16: Benchmark_Model_FeedManifests_Large

func Benchmark_Model_FeedManifests_Large(b *testing.B) {
	tree := fixtures.NewTree("collect-manifests-large-B", "")
	defer tree.Squash()
	assert.NoError(b, tree.Populate())
	assert.NoError(b, tree.PopulateN(1024*1024*500, 5))

	names := lists.NewFileList().ListDir(tree.CWD)

	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		b.StartTimer()
		m, err := model.New(tree.CWD, false, 1024*1024, 16)
		assert.NoError(b, err)
		lx, err := m.FeedManifests(true, true, true, names...)
		b.StopTimer()
		assert.NoError(b, err)
		for _, man := range lx {
			b.SetBytes(man.Size)
		}
	}
}
开发者ID:pombredanne,项目名称:bar,代码行数:21,代码来源:model_feed_test.go


示例17: Test_Storage_Upload_FinishUpload

func Test_Storage_Upload_FinishUpload(t *testing.T) {
	logx.SetLevel(logx.DEBUG)

	tree := fixtures.NewTree("finish-upload", "")
	defer tree.Squash()
	assert.NoError(t, tree.Populate())

	m, err := model.New(tree.CWD, false, proto.CHUNK_SIZE, 16)
	assert.NoError(t, err)

	os.RemoveAll("testdata/finish-upload-storage")
	stor := storage.NewBlockStorage(&storage.BlockStorageOptions{
		"testdata/finish-upload-storage", 2, 16, 32,
	})
	defer os.RemoveAll("testdata/finish-upload-storage")

	names := lists.NewFileList().ListDir(tree.CWD)
	mans, err := m.FeedManifests(true, false, true, names...)

	uID, _ := uuid.NewV4()
	missing, err := stor.CreateUploadSession(*uID, mans.GetManifestSlice(), time.Hour)
	assert.NoError(t, err)

	toUpload := mans.GetChunkLinkSlice(missing)

	for _, v := range toUpload {
		r, err := os.Open(tree.BlobFilename(v.Name))
		assert.NoError(t, err)
		defer r.Close()

		buf := make([]byte, v.Size)
		_, err = r.ReadAt(buf, v.Offset)

		err = stor.UploadChunk(*uID, v.Chunk.ID, bytes.NewReader(buf))
		assert.NoError(t, err)
	}

	err = stor.FinishUploadSession(*uID)
	assert.NoError(t, err)
}
开发者ID:pombredanne,项目名称:bar,代码行数:40,代码来源:upload_test.go


示例18: Run

func (c *GitDivertStatusCmd) Run(args ...string) (err error) {
	mod, err := model.New(c.WD, true, c.ChunkSize, c.PoolSize)
	if err != nil {
		return
	}

	divert := git.NewDivert(mod.Git)
	isInProgress, err := divert.IsInProgress()
	if err != nil {
		return
	}
	if !isInProgress {
		fmt.Fprintln(c.Stdout, "divert not in progress")
	}
	spec, err := divert.ReadSpec()
	if err != nil {
		return
	}
	fmt.Fprintln(c.Stdout, "DIVERT IN PROGRESS")
	fmt.Fprintln(c.Stdout, spec)

	return
}
开发者ID:pombredanne,项目名称:bar,代码行数:23,代码来源:git-divert-status.go


示例19: Test_Storage_Upload_CreateUpload

func Test_Storage_Upload_CreateUpload(t *testing.T) {
	logx.SetLevel(logx.DEBUG)

	tree := fixtures.NewTree("create-upload", "")
	defer tree.Squash()
	assert.NoError(t, tree.Populate())

	m, err := model.New(tree.CWD, false, proto.CHUNK_SIZE, 16)
	assert.NoError(t, err)

	os.RemoveAll("testdata/create-upload-storage")
	stor := storage.NewBlockStorage(&storage.BlockStorageOptions{
		"testdata/create-upload-storage", 2, 16, 32,
	})
	defer os.RemoveAll("testdata/create-upload-storage")

	names := lists.NewFileList().ListDir(tree.CWD)
	mans, err := m.FeedManifests(true, false, true, names...)

	uID, _ := uuid.NewV4()
	missing, err := stor.CreateUploadSession(*uID, mans.GetManifestSlice(), time.Hour)
	assert.NoError(t, err)
	assert.Len(t, missing, 4)
}
开发者ID:pombredanne,项目名称:bar,代码行数:24,代码来源:upload_test.go


示例20: Run

func (c *SpecImportCmd) Run(args ...string) (err error) {
	var spec proto.Spec

	mod, err := model.New(c.WD, c.UseGit, c.ChunkSize, c.PoolSize)
	if err != nil {
		return
	}
	trans := transport.NewTransport(mod, "", c.Endpoint, c.PoolSize)

	if c.Raw {
		if err = json.NewDecoder(c.Stdin).Decode(&spec); err != nil {
			return
		}
	} else {
		// tree spec types
		id := proto.ID(args[0])

		if spec, err = trans.GetSpec(id); err != nil {
			logx.Debug(spec, err)
			return
		}
	}

	idm := lists.IDMap{}
	for n, id := range spec.BLOBs {
		idm[id] = append(idm[id], n)
	}

	// request manifests and
	mans, err := trans.GetManifests(idm.IDs())
	if err != nil {
		return
	}
	feed := idm.ToBlobMap(mans)
	names := feed.Names()

	if len(names) == 0 {
		logx.Fatalf("no manifests on server %s", names)
	}

	logx.Debugf("importing %s", names)

	if c.UseGit {
		// If git is used - check names for attrs
		byAttr, err := mod.Git.FilterByAttr("bar", names...)
		if err != nil {
			return err
		}

		diff := []string{}
		attrs := map[string]struct{}{}
		for _, x := range byAttr {
			attrs[x] = struct{}{}
		}

		for _, x := range names {
			if _, ok := attrs[x]; !ok {
				diff = append(diff, x)
			}
		}
		if len(diff) > 0 {
			return fmt.Errorf("some spec blobs is not under bar control %s", diff)
		}
	}

	// get stored links, ignore errors
	stored, _ := mod.FeedManifests(true, true, false, names...)

	logx.Debugf("already stored %s", stored.Names())

	// squash present
	toSquash := lists.BlobMap{}
	for n, m := range feed {
		m1, ok := stored[filepath.FromSlash(n)]
		if !ok || m.ID != m1.ID {
			toSquash[n] = feed[n]
		}
	}

	if c.Squash {
		if err = mod.SquashBlobs(toSquash); err != nil {
			return
		}
	}
	for k, _ := range feed {
		fmt.Fprintf(c.Stdout, "%s ", filepath.FromSlash(k))
	}
	return
}
开发者ID:pombredanne,项目名称:bar,代码行数:89,代码来源:spec-import.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang proto.ID类代码示例发布时间:2022-05-24
下一篇:
Golang lists.NewFileList函数代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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