本文整理汇总了Golang中github.com/manishrjain/gocrud/x.Instruction类的典型用法代码示例。如果您正苦于以下问题:Golang Instruction类的具体用法?Golang Instruction怎么用?Golang Instruction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Instruction类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: ExampleIts
func ExampleIts() {
var its []x.Instruction
for t := 0; t < 10; t++ {
var i x.Instruction
i.NanoTs = int64(100 - t)
its = append(its, i)
}
sort.Sort(x.Its(its))
fmt.Println(its[0].NanoTs)
// Output: 91
}
开发者ID:ibmendoza,项目名称:gocrud,代码行数:13,代码来源:x_test.go
示例2: GetEntity
func (l *Leveldb) GetEntity(_, id string) (result []x.Instruction, rerr error) {
slice := util.BytesPrefix([]byte(id))
iter := l.db.NewIterator(slice, nil)
for iter.Next() {
buf := iter.Value()
if buf == nil {
break
}
var i x.Instruction
if err := i.GobDecode(buf); err != nil {
x.LogErr(log, err).Error("While decoding")
return result, err
}
result = append(result, i)
}
iter.Release()
err := iter.Error()
if err != nil {
x.LogErr(log, err).Error("While iterating")
}
return result, err
}
开发者ID:dancannon,项目名称:gocrud,代码行数:22,代码来源:leveldb.go
示例3: Iterate
func (l *Leveldb) Iterate(fromId string, num int,
ch chan x.Entity) (rnum int, rlast x.Entity, rerr error) {
slice := util.Range{Start: []byte(fromId)}
iter := l.db.NewIterator(&slice, nil)
rnum = 0
handled := make(map[x.Entity]bool)
for iter.Next() {
buf := iter.Value()
if buf == nil {
break
}
var i x.Instruction
if err := i.GobDecode(buf); err != nil {
x.LogErr(log, err).Error("While decoding")
return rnum, rlast, err
}
e := x.Entity{Kind: i.SubjectType, Id: i.SubjectId}
rlast = e
if _, present := handled[e]; present {
continue
}
ch <- e
handled[e] = true
rnum += 1
if rnum >= num {
break
}
}
iter.Release()
err := iter.Error()
if err != nil {
x.LogErr(log, err).Error("While iterating")
}
return rnum, rlast, err
}
开发者ID:ibmendoza,项目名称:gocrud,代码行数:36,代码来源:leveldb.go
示例4: ExampleInstruction
func ExampleInstruction() {
var i x.Instruction
i.SubjectId = "sid"
i.SubjectType = "stype"
b, err := i.GobEncode()
if err != nil {
panic(err)
}
var o x.Instruction
if err := o.GobDecode(b); err != nil {
panic(err)
}
fmt.Println(o.SubjectId)
fmt.Println(o.SubjectType)
// Output:
// sid
// stype
}
开发者ID:ibmendoza,项目名称:gocrud,代码行数:21,代码来源:x_test.go
示例5: doExecute
func (n *Update) doExecute(c *req.Context, its *[]*x.Instruction) error {
for pred, val := range n.edges {
if len(n.source) == 0 {
return errors.New(fmt.Sprintf(
"No source specified for id: %v kind: %v", n.id, n.kind))
}
i := new(x.Instruction)
i.SubjectId = n.id
i.SubjectType = n.kind
i.Predicate = pred
if b, err := json.Marshal(val); err != nil {
return err
} else {
i.Object = b
}
i.Source = n.source
i.NanoTs = n.NanoTs
log.WithField("instruction", i).Debug("Pushing to list")
*its = append(*its, i)
}
if len(n.children) == 0 {
return nil
}
if len(n.source) == 0 {
return errors.New(fmt.Sprintf(
"No source specified for id: %v kind: %v", n.id, n.kind))
}
// Children can only be added, not deleted via API. But they can be stopped
// from being retrieved.
// Scenario: How do I stop childA from being retrieved?
// Answer:
// Modify child by adding a 'deleted' edge
// Get(ChildKind, ChildId).Set("deleted", true).Execute(c)
//
// Then for retrieval from parent:
// NewQuery(ParentKind, ParentId).Collect(ChildKind).FilterOut("deleted")
// This would remove all children with a 'deleted' edge.
// Better still
// Get(ChildKind, ChildId).MarkDeleted().Execute(c)
// would automatically filter out that child and it's children
// from being retrieved.
for _, child := range n.children {
if len(child.id) > 0 {
log.WithField("child_id", child.id).Fatal(
"Child id should be empty for all current use cases")
return errors.New("Non empty child id")
}
for idx := 0; ; idx++ { // Retry loop.
child.id = x.UniqueString(c.NumCharsUnique)
log.WithField("id", child.id).Debug("Checking availability of new id")
if isnew := Get().IsNew(child.id); isnew {
log.WithField("id", child.id).Debug("New id available")
break
}
if idx >= 30 {
return errors.New("Unable to find new id")
}
}
// Create edge from parent to child
i := new(x.Instruction)
i.SubjectId = n.id
i.SubjectType = n.kind
i.Predicate = child.kind
i.ObjectId = child.id
i.Source = n.source
i.NanoTs = n.NanoTs
log.WithField("instruction", i).Debug("Pushing to list")
*its = append(*its, i)
// Create edge from child to parent
i = new(x.Instruction)
i.SubjectId = child.id
i.SubjectType = child.kind
i.Predicate = "_parent_"
i.ObjectId = n.id
i.Source = n.source
i.NanoTs = n.NanoTs
log.WithField("instruction", i).Debug("Pushing to list")
*its = append(*its, i)
if err := child.doExecute(c, its); err != nil {
return err
}
}
return nil
}
开发者ID:ibmendoza,项目名称:gocrud,代码行数:92,代码来源:update.go
注:本文中的github.com/manishrjain/gocrud/x.Instruction类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论