本文整理汇总了Golang中github.com/cockroachdb/cockroach/proto.Key.String方法的典型用法代码示例。如果您正苦于以下问题:Golang Key.String方法的具体用法?Golang Key.String怎么用?Golang Key.String使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/cockroachdb/cockroach/proto.Key
的用法示例。
在下文中一共展示了Key.String方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: writeDescriptor
// writeDescriptor takes a Table or Database descriptor and writes it
// if needed, incrementing the descriptor counter.
func (p *planner) writeDescriptor(key proto.Key, descriptor descriptorProto, ifNotExists bool) error {
// Check whether key exists.
gr, err := p.db.Get(key)
if err != nil {
return err
}
if gr.Exists() {
if ifNotExists {
// Noop.
return nil
}
// Key exists, but we don't want it to: error out.
// TODO(marc): prettify the error (strip stuff off the type name)
return fmt.Errorf("%T \"%s\" already exists", descriptor, key.String())
}
// Increment unique descriptor counter.
if ir, err := p.db.Inc(keys.DescIDGenerator, 1); err == nil {
descriptor.SetID(uint32(ir.ValueInt() - 1))
} else {
return err
}
// TODO(pmattis): The error currently returned below is likely going to be
// difficult to interpret.
// TODO(pmattis): Need to handle if-not-exists here as well.
descKey := keys.MakeDescMetadataKey(descriptor.GetID())
return p.db.Txn(func(txn *client.Txn) error {
b := &client.Batch{}
b.CPut(key, descKey, nil)
b.CPut(descKey, descriptor, nil)
return txn.Commit(b)
})
}
示例2: getDescriptor
// getDescriptor looks up the descriptor at `key`, validates it,
// and unmarshals it into `descriptor`.
func (p *planner) getDescriptor(key proto.Key, descriptor descriptorProto) error {
gr, err := p.db.Get(key)
if err != nil {
return err
}
if !gr.Exists() {
// TODO(marc): prettify the error (strip stuff off the type name)
return fmt.Errorf("%T \"%s\" does not exist", descriptor, key.String())
}
descKey := gr.ValueBytes()
if err := p.db.GetProto(descKey, descriptor); err != nil {
return err
}
return descriptor.Validate()
}