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

Golang cayley.StartPath函数代码示例

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

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



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

示例1: TestSave

func (suite *GraphTestSuite) TestSave(t *C) {
	mTime := time.Now()
	ni := graph.NodeInfo{
		Name:     "child",
		ParentId: graph.RootNodeId,
		Mode:     os.FileMode(0755),
		MTime:    mTime,
		Type:     "application/json",
	}

	node, err := suite.ng.NewNodeWithNodeInfo(ni)
	t.Check(err, IsNil)

	assertProperty := func(expected string, actual cayley.Iterator) {
		t.Check(cayley.RawNext(actual), Equals, true)
		t.Check(suite.ng.NameOf(actual.Result()), Equals, expected)
	}

	it := cayley.StartPath(suite.ng, node.Id).Out("isNamed").BuildIterator()
	assertProperty("child", it)

	it = cayley.StartPath(suite.ng, node.Id).Out("hasMTime").BuildIterator()
	assertProperty(mTime.Format(time.RFC3339Nano), it)

	it = cayley.StartPath(suite.ng, node.Id).Out("hasMode").BuildIterator()
	assertProperty(fmt.Sprint(0755), it)

	it = cayley.StartPath(suite.ng, node.Id).Out("hasType").BuildIterator()
	assertProperty("application/json", it)
}
开发者ID:sdcoffey,项目名称:Olympus,代码行数:30,代码来源:node_test.go


示例2: toLayers

// toLayers converts a path leading to one or multiple layers to Layer structs,
// selecting the specified fields
func toLayers(path *path.Path, selectedFields []string) ([]*Layer, error) {
	var layers []*Layer

	saveFields(path, selectedFields, []string{FieldLayerSuccessors, FieldLayerPackages, FieldLayerInstalledPackages, FieldLayerRemovedPackages})
	it, _ := path.BuildIterator().Optimize()
	defer it.Close()
	for cayley.RawNext(it) {
		tags := make(map[string]graph.Value)
		it.TagResults(tags)

		layer := Layer{Node: store.NameOf(it.Result())}
		for _, selectedField := range selectedFields {
			switch selectedField {
			case FieldLayerID:
				layer.ID = store.NameOf(tags[FieldLayerID])
			case FieldLayerParent:
				layer.ParentNode = store.NameOf(tags[FieldLayerParent])
			case FieldLayerSuccessors:
				var err error
				layer.SuccessorsNodes, err = toValues(cayley.StartPath(store, layer.Node).In(FieldLayerParent))
				if err != nil {
					log.Errorf("could not get successors of layer %s: %s.", layer.Node, err.Error())
					return nil, err
				}
			case FieldLayerOS:
				layer.OS = store.NameOf(tags[FieldLayerOS])
			case FieldLayerPackages:
				var err error
				it, _ := cayley.StartPath(store, layer.Node).OutWithTags([]string{"predicate"}, FieldLayerInstalledPackages, FieldLayerRemovedPackages).BuildIterator().Optimize()
				defer it.Close()
				for cayley.RawNext(it) {
					tags := make(map[string]graph.Value)
					it.TagResults(tags)

					predicate := store.NameOf(tags["predicate"])
					if predicate == FieldLayerInstalledPackages {
						layer.InstalledPackagesNodes = append(layer.InstalledPackagesNodes, store.NameOf(it.Result()))
					} else if predicate == FieldLayerRemovedPackages {
						layer.RemovedPackagesNodes = append(layer.RemovedPackagesNodes, store.NameOf(it.Result()))
					}
				}
				if it.Err() != nil {
					log.Errorf("could not get installed/removed packages of layer %s: %s.", layer.Node, it.Err())
					return nil, err
				}
			case FieldLayerEngineVersion:
				layer.EngineVersion, _ = strconv.Atoi(store.NameOf(tags[FieldLayerEngineVersion]))
			default:
				panic("unknown selectedField")
			}
		}
		layers = append(layers, &layer)
	}
	if it.Err() != nil {
		log.Errorf("failed query in toLayers: %s", it.Err())
		return []*Layer{}, ErrBackendException
	}

	return layers, nil
}
开发者ID:kinvolk,项目名称:clair,代码行数:62,代码来源:layer.go


示例3: NodeWithName

func (ng *NodeGraph) NodeWithName(parentId, name string) *Node {
	namePath := cayley.StartPath(ng, name).In(nameLink)
	parentpath := cayley.StartPath(ng, parentId).In(parentLink)

	it := namePath.And(parentpath).BuildIterator()
	if cayley.RawNext(it) {
		return ng.NodeWithId(ng.NameOf(it.Result()))
	}

	return nil
}
开发者ID:sdcoffey,项目名称:Olympus,代码行数:11,代码来源:nodegraph.go


示例4: FindAllLayersByAddedPackageNodes

// FindAllLayersByAddedPackageNodes finds and returns all layers that add the
// given packages (by their nodes), selecting the specified fields
func FindAllLayersByAddedPackageNodes(nodes []string, selectedFields []string) ([]*Layer, error) {
	layers, err := toLayers(cayley.StartPath(store, nodes...).In(FieldLayerInstalledPackages), selectedFields)
	if err != nil {
		return []*Layer{}, err
	}
	return layers, nil
}
开发者ID:kinvolk,项目名称:clair,代码行数:9,代码来源:layer.go


示例5: Unlock

// Unlock unlocks a lock specified by its name if I own it
func Unlock(name, owner string) {
	unlocked := 0
	it, _ := cayley.StartPath(store, name).Has(fieldLockLocked, fieldLockLockedValue).Has(fieldLockLockedBy, owner).Save(fieldLockLockedUntil, fieldLockLockedUntil).BuildIterator().Optimize()
	defer it.Close()
	for cayley.RawNext(it) {
		tags := make(map[string]graph.Value)
		it.TagResults(tags)

		t := cayley.NewTransaction()
		t.RemoveQuad(cayley.Triple(name, fieldLockLocked, fieldLockLockedValue))
		t.RemoveQuad(cayley.Triple(name, fieldLockLockedUntil, store.NameOf(tags[fieldLockLockedUntil])))
		t.RemoveQuad(cayley.Triple(name, fieldLockLockedBy, owner))
		err := store.ApplyTransaction(t)
		if err != nil {
			log.Errorf("failed transaction (Unlock): %s", err)
		}

		unlocked++
	}
	if it.Err() != nil {
		log.Errorf("failed query in Unlock: %s", it.Err())
	}
	if unlocked > 1 {
		// We should never see this, it would mean that our database doesn't ensure quad uniqueness
		// and that the entire lock system is jeopardized.
		log.Errorf("found inconsistency in Unlock: matched %d times a locked named: %s", unlocked, name)
	}
}
开发者ID:dwdm,项目名称:clair,代码行数:29,代码来源:lock.go


示例6: FindAllVulnerabilitiesByFixedIn

// FindAllVulnerabilitiesByFixedIn finds and returns all vulnerabilities that are fixed in the given packages (speficied by their nodes), selecting the specified fields
func FindAllVulnerabilitiesByFixedIn(nodes []string, selectedFields []string) ([]*Vulnerability, error) {
	if len(nodes) == 0 {
		log.Warning("Could not FindAllVulnerabilitiesByFixedIn with an empty nodes array.")
		return []*Vulnerability{}, nil
	}
	return toVulnerabilities(cayley.StartPath(store, nodes...).In(FieldVulnerabilityFixedIn), selectedFields)
}
开发者ID:ruo91,项目名称:clair,代码行数:8,代码来源:vulnerability.go


示例7: main

func main() {

	store, err := cayley.NewGraph("bolt", dbPath, nil)
	if err != nil {
		fmt.Println("error in creating database", err)
	}

	path := cayley.StartPath(store, "Article").
		In().
		Tag("link").
		Save("has_image", "image").
		Save("has_title", "title").
		Save("has_description", "description")

	it := path.BuildIterator()
	it, _ = it.Optimize()

	for graph.Next(it) {
		tags := make(map[string]graph.Value)
		it.TagResults(tags)
		fmt.Println(store.NameOf(tags["image"]))
		fmt.Println(store.NameOf(tags["title"]))
		fmt.Println(store.NameOf(tags["description"]))
		fmt.Println(store.NameOf(tags["link"]))
	}

}
开发者ID:paritosh-gupta,项目名称:ArticleFinder,代码行数:27,代码来源:cayleyQueryApiTest.go


示例8: FindAllPackagesByNodes

// FindAllPackagesByNodes finds and returns all packages given by their nodes, selecting the specified fields
func FindAllPackagesByNodes(nodes []string, selectedFields []string) ([]*Package, error) {
	if len(nodes) == 0 {
		return []*Package{}, nil
	}

	return toPackages(cayley.StartPath(store, nodes...).Has(FieldIs, FieldPackageIsValue), selectedFields)
}
开发者ID:neujie,项目名称:clair,代码行数:8,代码来源:package.go


示例9: SearchForArticles

/*
* Searches for articles in the database
* @param tags string[] The tags entered by the user.Currently only entity search has been implemented.
Algorithm in Readme
*/
func SearchForArticles(tags []string, store *cayley.Handle) PairList {
	links := make(map[string]int)

	for _, tag := range tags {

		entities := extractArticleData.GetEntityInfo(tag, "")

		if len(entities) == 0 {
			continue
		}

		entitityInfo := entities[0] // Get the First Entity //TODO:- Change to Best Label Match

		for _, category := range entitityInfo.Categories {

			path := cayley.StartPath(store, category).
				In("has_category").
				In("has_entity")

			it := path.BuildIterator()
			it, _ = it.Optimize()

			for cayley.RawNext(it) {
				link := store.NameOf(it.Result())
				links[link] += 10
			}
		}
	}
	return sortMapByValue(links)
}
开发者ID:paritosh-gupta,项目名称:ArticleFinder,代码行数:35,代码来源:search.go


示例10: AddServiceHost

func (s *localSignallingLayer) AddServiceHost(service string, version string, uri string) (common.ServiceHost, error) {
	var h, err = s.base.AddServiceHost(service, version, uri)
	if err == nil {
		var svcDef, finderr = s.base.GetServiceDefinition(service)
		if finderr == nil {
			// find all affected api versions
			var startingNodeID = utils.CreateServiceVersionKey(service, version)
			var path = cayley.StartPath(s.graph, startingNodeID).Out(utils.InApiRel)
			it := path.BuildIterator()
			for cayley.RawNext(it) {
				var apiNodeID = s.graph.NameOf(it.Result())
				var apiVersion = strings.TrimPrefix(apiNodeID, utils.CreateAPIVersionKey(""))
				var event = common.Event{}
				event.ActionCode = "ADD_ServiceHost"
				event.Data = map[string]string{
					"version": apiVersion,
					"prefix":  svcDef.Prefix,
					"uri":     uri}
				s.signalOutput <- event
			}
		}
	}

	return h, err
}
开发者ID:enzian,项目名称:msf-tools,代码行数:25,代码来源:LocalSignaller.go


示例11: pruneLocks

// pruneLocks removes every expired locks from the database
func pruneLocks() {
	now := time.Now()

	// Delete every expired locks
	it, _ := cayley.StartPath(store, "locked").In("locked").Save(fieldLockLockedUntil, fieldLockLockedUntil).Save(fieldLockLockedBy, fieldLockLockedBy).BuildIterator().Optimize()
	defer it.Close()
	for cayley.RawNext(it) {
		tags := make(map[string]graph.Value)
		it.TagResults(tags)

		n := store.NameOf(it.Result())
		t := store.NameOf(tags[fieldLockLockedUntil])
		o := store.NameOf(tags[fieldLockLockedBy])
		tt, _ := strconv.ParseInt(t, 10, 64)

		if now.Unix() > tt {
			log.Debugf("lock %s owned by %s has expired.", n, o)

			tr := cayley.NewTransaction()
			tr.RemoveQuad(cayley.Triple(n, fieldLockLocked, fieldLockLockedValue))
			tr.RemoveQuad(cayley.Triple(n, fieldLockLockedUntil, t))
			tr.RemoveQuad(cayley.Triple(n, fieldLockLockedBy, o))
			err := store.ApplyTransaction(tr)
			if err != nil {
				log.Errorf("failed transaction (pruneLocks): %s", err)
				continue
			}
			log.Debugf("lock %s has been successfully pruned.", n)
		}
	}
	if it.Err() != nil {
		log.Errorf("failed query in Unlock: %s", it.Err())
	}
}
开发者ID:dwdm,项目名称:clair,代码行数:35,代码来源:lock.go


示例12: pruneLocks

// pruneLocks removes every expired locks from the database
func pruneLocks() {
	now := time.Now()

	// Delete every expired locks
	tr := cayley.NewTransaction()
	it, _ := cayley.StartPath(store, "locked").In("locked").Save("locked_until", "locked_until").Save("locked_by", "locked_by").BuildIterator().Optimize()
	defer it.Close()
	for cayley.RawNext(it) {
		tags := make(map[string]graph.Value)
		it.TagResults(tags)

		n := store.NameOf(it.Result())
		t := store.NameOf(tags["locked_until"])
		o := store.NameOf(tags["locked_by"])
		tt, _ := strconv.ParseInt(t, 10, 64)

		if now.Unix() > tt {
			log.Debugf("Lock %s owned by %s has expired.", n, o)
			tr.RemoveQuad(cayley.Quad(n, "locked", "locked", ""))
			tr.RemoveQuad(cayley.Quad(n, "locked_until", t, ""))
			tr.RemoveQuad(cayley.Quad(n, "locked_by", o, ""))
		}
	}
	store.ApplyTransaction(tr)
}
开发者ID:ruo91,项目名称:clair,代码行数:26,代码来源:lock.go


示例13: Lock

// Lock tries to set a temporary lock in the database.
// If a lock already exists with the given name/owner, then the lock is renewed
//
// Lock does not block, instead, it returns true and its expiration time
// is the lock has been successfully acquired or false otherwise
func Lock(name string, duration time.Duration, owner string) (bool, time.Time) {
	pruneLocks()

	until := time.Now().Add(duration)
	untilString := strconv.FormatInt(until.Unix(), 10)

	// Try to get the expiration time of a lock with the same name/owner
	currentExpiration, err := toValue(cayley.StartPath(store, name).Has("locked_by", owner).Out("locked_until"))
	if err == nil && currentExpiration != "" {
		// Renew our lock
		if currentExpiration == untilString {
			return true, until
		}

		t := cayley.NewTransaction()
		t.RemoveQuad(cayley.Quad(name, "locked_until", currentExpiration, ""))
		t.AddQuad(cayley.Quad(name, "locked_until", untilString, ""))
		// It is not necessary to verify if the lock is ours again in the transaction
		// because if someone took it, the lock's current expiration probably changed and the transaction will fail
		return store.ApplyTransaction(t) == nil, until
	}

	t := cayley.NewTransaction()
	t.AddQuad(cayley.Quad(name, "locked", "locked", "")) // Necessary to make the transaction fails if the lock already exists (and has not been pruned)
	t.AddQuad(cayley.Quad(name, "locked_until", untilString, ""))
	t.AddQuad(cayley.Quad(name, "locked_by", owner, ""))

	glog.SetStderrThreshold("FATAL")
	success := store.ApplyTransaction(t) == nil
	glog.SetStderrThreshold("ERROR")

	return success, until
}
开发者ID:ruo91,项目名称:clair,代码行数:38,代码来源:lock.go


示例14: FindAllPackagesByNodes

// FindAllPackagesByNodes finds and returns all packages given by their nodes, selecting the specified fields
func FindAllPackagesByNodes(nodes []string, selectedFields []string) ([]*Package, error) {
	if len(nodes) == 0 {
		log.Warning("could not FindAllPackagesByNodes with an empty nodes array.")
		return []*Package{}, nil
	}

	return toPackages(cayley.StartPath(store, nodes...).Has(FieldIs, FieldPackageIsValue), selectedFields)
}
开发者ID:kinvolk,项目名称:clair,代码行数:9,代码来源:package.go


示例15: graphValue

func (nd *Node) graphValue(key string) (value string) {
	it := cayley.StartPath(nd.graph, nd.Id).Out(key).BuildIterator()
	if cayley.RawNext(it) {
		value = nd.graph.NameOf(it.Result())
	}

	return
}
开发者ID:sdcoffey,项目名称:Olympus,代码行数:8,代码来源:node.go


示例16: NotifyStop

func (s *SocketServer) NotifyStop(t int64) {
	stopAt := strconv.FormatInt(t, 10)
	p := cayley.StartPath(s.storage, stopAt).In("free at")
	it := p.BuildIterator()
	for cayley.RawNext(it) {
		s.BroadcastTo(RoomName, "stop", s.storage.NameOf(it.Result()))
	}
}
开发者ID:gophergala2016,项目名称:Pomodoro_Crew,代码行数:8,代码来源:server.go


示例17: NotifyEnable

func (s *SocketServer) NotifyEnable(t int64) {
	stopedAt := strconv.FormatInt(t-models.Wait5Minutes, 10)
	p := cayley.StartPath(s.storage, stopedAt).In("free at")
	it := p.BuildIterator()
	for cayley.RawNext(it) {
		//TODO send to only one user
		s.BroadcastTo(RoomName, "enable", s.storage.NameOf(it.Result()))
	}
}
开发者ID:gophergala2016,项目名称:Pomodoro_Crew,代码行数:9,代码来源:server.go


示例18: GetProfilePerm

func (a *ACL) GetProfilePerm(sourceprofileid, targetprofile string) []string {
	p := cayley.StartPath(a.profilestore, sourceprofileid).Out(targetprofile)
	it := p.BuildIterator()
	r := []string{}
	for cayley.RawNext(it) {
		r = append(r, a.profilestore.NameOf(it.Result()))
	}
	return r
}
开发者ID:pombredanne,项目名称:cayley-acl-test,代码行数:9,代码来源:acl.go


示例19: TestToValue

func TestToValue(t *testing.T) {
	Open(&config.DatabaseConfig{Type: "memstore"})
	defer Close()

	// toValue()
	v, err := toValue(cayley.StartPath(store, "tests").Out("are"))
	assert.Nil(t, err, "toValue should work even if the requested path leads to nothing")
	assert.Equal(t, "", v, "toValue should return an empty string if the requested path leads to nothing")

	store.AddQuad(cayley.Triple("tests", "are", "awesome"))
	v, err = toValue(cayley.StartPath(store, "tests").Out("are"))
	assert.Nil(t, err, "toValue should have worked")
	assert.Equal(t, "awesome", v, "toValue did not return the expected value")

	store.AddQuad(cayley.Triple("tests", "are", "running"))
	v, err = toValue(cayley.StartPath(store, "tests").Out("are"))
	assert.NotNil(t, err, "toValue should return an error and an empty string if the path leads to multiple values")
	assert.Equal(t, "", v, "toValue should return an error and an empty string if the path leads to multiple values")

	// toValues()
	vs, err := toValues(cayley.StartPath(store, "CoreOS").Out(fieldIs))
	assert.Nil(t, err, "toValues should work even if the requested path leads to nothing")
	assert.Len(t, vs, 0, "toValue should return an empty array if the requested path leads to nothing")
	words := []string{"powerful", "lightweight"}
	for i, word := range words {
		store.AddQuad(cayley.Triple("CoreOS", fieldIs, word))
		v, err := toValues(cayley.StartPath(store, "CoreOS").Out(fieldIs))
		assert.Nil(t, err, "toValues should have worked")
		assert.Len(t, v, i+1, "toValues did not return the right amount of values")
		for _, e := range words[:i+1] {
			assert.Contains(t, v, e, "toValues did not return the values we expected")
		}
	}

	// toValue(s)() and empty values
	store.AddQuad(cayley.Triple("bob", "likes", ""))
	v, err = toValue(cayley.StartPath(store, "bob").Out("likes"))
	assert.Nil(t, err, "toValue should work even if the requested path leads to nothing")
	assert.Equal(t, "", v, "toValue should return an empty string if the requested path leads to nothing")

	store.AddQuad(cayley.Triple("bob", "likes", "running"))
	v, err = toValue(cayley.StartPath(store, "bob").Out("likes"))
	assert.NotNil(t, err, "toValue should return an error and an empty string if the path leads to multiple values")
	assert.Equal(t, "", v, "toValue should return an error and an empty string if the path leads to multiple values")

	store.AddQuad(cayley.Triple("bob", "likes", "swimming"))
	va, err := toValues(cayley.StartPath(store, "bob").Out("likes"))
	assert.Nil(t, err, "toValues should have worked")
	if assert.Len(t, va, 3, "toValues should have returned 2 values") {
		assert.Contains(t, va, "running")
		assert.Contains(t, va, "swimming")
		assert.Contains(t, va, "")
	}
}
开发者ID:dwdm,项目名称:clair,代码行数:54,代码来源:database_test.go


示例20: GetUsersFreeAt

func (s *Storage) GetUsersFreeAt(t int64) []*User {
	freeAt := strconv.FormatInt(t, 10)

	users := []*User{}
	p := cayley.StartPath(s, freeAt).In("free at")
	it := p.BuildIterator()
	for cayley.RawNext(it) {
		users = append(users, NewUser(s.NameOf(it.Result())))
	}

	return users
}
开发者ID:gophergala2016,项目名称:Pomodoro_Crew,代码行数:12,代码来源:Storage.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang graph.ContainsLogIn函数代码示例发布时间:2022-05-23
下一篇:
Golang cayley.RawNext函数代码示例发布时间: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