本文整理匯總了Golang中github.com/google/cayley.RawNext函數的典型用法代碼示例。如果您正苦於以下問題:Golang RawNext函數的具體用法?Golang RawNext怎麽用?Golang RawNext使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了RawNext函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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
}
示例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)
}
示例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
}
示例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)
}
示例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)
}
}
示例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)
}
示例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())
}
}
示例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()))
}
}
示例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
}
示例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()))
}
}
示例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
}
示例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
}
示例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 ""
}
}
示例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
}
示例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), ""))
}