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


Golang model.New函数代码示例

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


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


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