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

Golang cayley.RawNext函数代码示例

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

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



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

示例1: 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


示例2: 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


示例3: 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


示例4: 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


示例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: 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


示例7: 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


示例8: 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


示例9: 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


示例10: 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


示例11: 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


示例12: 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


示例13: BlockWithOffset

func (nd *Node) BlockWithOffset(offset int64) string {
	if nd.IsDir() {
		return ""
	}

	it := cayley.StartPath(nd.graph, nd.Id).Out(fmt.Sprint("offset-", offset)).BuildIterator()
	if cayley.RawNext(it) {
		return nd.graph.NameOf(it.Result())
	} else {
		return ""
	}
}
开发者ID:sdcoffey,项目名称:Olympus,代码行数:12,代码来源:node.go


示例14: 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


示例15: SaveUser

func (s *Storage) SaveUser(u *User) {
	s.AddQuad(cayley.Quad(u.Name, "is", "user", ""))

	p := cayley.StartPath(u.getStorage(), u.Name).Out("free at")

	iterationTime := u.IterationTime()
	it := p.BuildIterator()
	for cayley.RawNext(it) {
		s.RemoveQuad(cayley.Quad(u.Name, "free at", s.NameOf(it.Result()), ""))
	}

	s.AddQuad(cayley.Quad(u.Name, "free at", strconv.FormatInt(iterationTime, 10), ""))
}
开发者ID:gophergala2016,项目名称:Pomodoro_Crew,代码行数:13,代码来源:Storage.go


示例16: TestWriteData_removesExistingFingerprintForOffset

func (suite *GraphTestSuite) TestWriteData_removesExistingFingerprintForOffset(t *C) {
	child, _ := makeNode("child", suite.ng.RootNode.Id, time.Now(), suite.ng)
	dat := testutils.RandDat(1024)

	t.Check(child.WriteData(dat, 0), IsNil)

	dat = testutils.RandDat(1024)
	fingerprint := graph.Hash(dat)
	t.Check(child.WriteData(dat, 0), IsNil)

	it := cayley.StartPath(suite.ng, child.Id).Out("offset-0").BuildIterator()
	t.Check(cayley.RawNext(it), Equals, true)
	t.Check(suite.ng.NameOf(it.Result()), Equals, fingerprint)
}
开发者ID:sdcoffey,项目名称:Olympus,代码行数:14,代码来源:node_test.go


示例17: IterationTime

func (u *User) IterationTime() int64 {
	if u.iterationTime == 0 {
		p := cayley.StartPath(u.getStorage(), u.Name).Out("free at")

		it := p.BuildIterator()
		if cayley.RawNext(it) {
			u.iterationTime, _ = strconv.ParseInt(u.getStorage().NameOf(it.Result()), 10, 64)
		} else {
			u.iterationTime = time.Now().Unix() - Wait5Minutes
		}
	}

	return u.iterationTime
}
开发者ID:gophergala2016,项目名称:Pomodoro_Crew,代码行数:14,代码来源:User.go


示例18: CountNotificationsToSend

// CountNotificationsToSend returns the number of pending notifications
// Note that it also count the locked notifications.
func CountNotificationsToSend() (int, error) {
	c := 0

	it, _ := cayley.StartPath(store, "notification").In(FieldIs).Has("isSent", strconv.FormatBool(false)).BuildIterator().Optimize()
	defer it.Close()
	for cayley.RawNext(it) {
		c = c + 1
	}
	if it.Err() != nil {
		log.Errorf("failed query in CountNotificationsToSend: %s", it.Err())
		return 0, ErrBackendException
	}

	return c, nil
}
开发者ID:ruo91,项目名称:clair,代码行数:17,代码来源:notification.go


示例19: loadVersionsByAPI

func (p *mgoPersistenceProvider) loadVersionsByAPI(apiVersion string, graph *cayley.Handle, session *mgo.Session, target common.IServiceRegistry) error {
	var startingNodeID = utils.CreateAPIVersionKey(apiVersion)
	var path = cayley.StartPath(graph, startingNodeID).Out(utils.ContainsVersionRel)
	it := path.BuildIterator()
	for cayley.RawNext(it) {
		var version serviceVersion
		err := session.DB("test").C("serviceVersions").Find(bson.M{"_id": graph.NameOf(it.Result())}).One(&version)
		if err != nil {
			return err
		}
		target.LinkServiceToAPI(version.Service, version.Version, apiVersion)
	}

	return nil
}
开发者ID:enzian,项目名称:msf-tools,代码行数:15,代码来源:MgoPersistenceProvider.go


示例20: loadVersionsByService

func (p *mgoPersistenceProvider) loadVersionsByService(serviceIdentifier string, graph *cayley.Handle, session *mgo.Session, target common.IServiceRegistry) error {
	var startingNodeID = utils.CreateServiceDefinitionKey(serviceIdentifier)
	var path = cayley.StartPath(graph, startingNodeID).Out(utils.ContainsVersionRel)
	it := path.BuildIterator()
	for cayley.RawNext(it) {
		var version serviceVersion
		var serviceVersionNode = graph.NameOf(it.Result())
		err := session.DB("test").C("serviceVersions").Find(bson.M{"_id": serviceVersionNode}).One(&version)
		if err != nil {
			return fmt.Errorf("Cannot find %s in collection 'serviceVersions': %s", serviceVersionNode, err.Error())
		}
		target.AddServiceVersion(serviceIdentifier, version.Version)
	}

	return nil
}
开发者ID:enzian,项目名称:msf-tools,代码行数:16,代码来源:MgoPersistenceProvider.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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