本文整理匯總了Golang中code/google/com/p/go-uuid/uuid.UUID類的典型用法代碼示例。如果您正苦於以下問題:Golang UUID類的具體用法?Golang UUID怎麽用?Golang UUID使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了UUID類的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Delete
func (p *MemoryPersistence) Delete(client string, direction dirFlag, uid uuid.UUID) bool {
//only need to get a read lock on the persistence store, but lock the underlying
//persistenceentry for the client we're working with.
p.RLock()
defer p.RUnlock()
//checks that there is actually an entry for the message id we're being asked to
//delete, if there isn't return false, otherwise delete the entry.
id := uid.String()
DEBUG.Println("Removing persisted message for", client)
switch direction {
case INBOUND:
p.inbound[client].Lock()
defer p.inbound[client].Unlock()
//if there is already an entry for this message id return false
if _, ok := p.inbound[client].messages[id]; !ok {
return false
}
delete(p.inbound[client].messages, id)
case OUTBOUND:
p.outbound[client].Lock()
defer p.outbound[client].Unlock()
//if there is already an entry for this message id return false
if _, ok := p.outbound[client].messages[id]; !ok {
return false
}
delete(p.outbound[client].messages, id)
}
return true
}
示例2: LoadSuperblock
func (bs *BlockStore) LoadSuperblock(id uuid.UUID, generation uint64) *Superblock {
var sb = fake_sblock{}
if generation == LatestGeneration {
//log.Info("loading superblock uuid=%v (lgen)", id.String())
qry := bs.db.C("superblocks").Find(bson.M{"uuid": id.String()})
if err := qry.Sort("-gen").One(&sb); err != nil {
if err == mgo.ErrNotFound {
lg.Info("sb notfound!")
return nil
} else {
lg.Panic(err)
}
}
} else {
qry := bs.db.C("superblocks").Find(bson.M{"uuid": id.String(), "gen": generation})
if err := qry.One(&sb); err != nil {
if err == mgo.ErrNotFound {
return nil
} else {
lg.Panic(err)
}
}
}
rv := Superblock{
uuid: id,
gen: sb.Gen,
root: sb.Root,
unlinked: sb.Unlinked,
}
return &rv
}
示例3: GetByUuid
func (db *InMemDatabase) GetByUuid(id uuid.UUID) (contrail.IObject, error) {
uid := makeUID(id)
obj, ok := db.objByIdMap[uid]
if !ok {
return nil, fmt.Errorf("%s: Not found", id.String())
}
return obj, nil
}
示例4: newPod
func newPod(h *Host, id uuid.UUID) *Pod {
if id == nil {
id = uuid.NewRandom()
}
return &Pod{
Host: h,
UUID: id,
ui: ui.NewUI("yellow", "pod", id.String()),
}
}
示例5: NewImage
func NewImage(h *Host, id uuid.UUID) *Image {
if id == nil {
id = uuid.NewRandom()
}
return &Image{
Host: h,
UUID: id,
Manifest: *schema.BlankImageManifest(),
ui: ui.NewUI("blue", "image", id.String()),
}
}
示例6: UnlinkGenerations
func (bs *BlockStore) UnlinkGenerations(id uuid.UUID, sgen uint64, egen uint64) error {
iter := bs.db.C("superblocks").Find(bson.M{"uuid": id.String(), "gen": bson.M{"$gte": sgen, "$lt": egen}, "unlinked": false}).Iter()
rs := fake_sblock{}
for iter.Next(&rs) {
rs.Unlinked = true
_, err := bs.db.C("superblocks").Upsert(bson.M{"uuid": id.String(), "gen": rs.Gen}, rs)
if err != nil {
lg.Panic(err)
}
}
return nil
}
示例7: DEBUG_DELETE_UUID
func (bs *BlockStore) DEBUG_DELETE_UUID(id uuid.UUID) {
lg.Info("DEBUG removing uuid '%v' from database", id.String())
_, err := bs.db.C("superblocks").RemoveAll(bson.M{"uuid": id.String()})
if err != nil && err != mgo.ErrNotFound {
lg.Panic(err)
}
if err == mgo.ErrNotFound {
lg.Info("Quey did not find supeblock to delete")
} else {
lg.Info("err was nik")
}
//bs.datablockBarrier()
}
示例8: ObtainGeneration
/*
* This obtains a generation, blocking if necessary
*/
func (bs *BlockStore) ObtainGeneration(id uuid.UUID) *Generation {
//The first thing we do is obtain a write lock on the UUID, as a generation
//represents a lock
mk := UUIDToMapKey(id)
bs.glock.RLock()
mtx, ok := bs._wlocks[mk]
bs.glock.RUnlock()
if !ok {
//Mutex doesn't exist so is unlocked
mtx := new(sync.Mutex)
mtx.Lock()
bs.glock.Lock()
bs._wlocks[mk] = mtx
bs.glock.Unlock()
} else {
mtx.Lock()
}
gen := &Generation{
cblocks: make([]*Coreblock, 0, 8192),
vblocks: make([]*Vectorblock, 0, 8192),
}
//We need a generation. Lets see if one is on disk
qry := bs.db.C("superblocks").Find(bson.M{"uuid": id.String()})
rs := fake_sblock{}
qerr := qry.Sort("-gen").One(&rs)
if qerr == mgo.ErrNotFound {
lg.Info("no superblock found for %v", id.String())
//Ok just create a new superblock/generation
gen.Cur_SB = NewSuperblock(id)
} else if qerr != nil {
//Well thats more serious
lg.Panic("Mongodb error: %v", qerr)
} else {
//Ok we have a superblock, pop the gen
//log.Info("Found a superblock for %v", id.String())
sb := Superblock{
uuid: id,
root: rs.Root,
gen: rs.Gen,
}
gen.Cur_SB = &sb
}
gen.New_SB = gen.Cur_SB.Clone()
gen.New_SB.gen = gen.Cur_SB.gen + 1
gen.blockstore = bs
return gen
}
示例9: new_peer
func new_peer(uuid uuid.UUID) (peer *peer_t) {
peer = &peer_t{
uuid_bytes: []byte(uuid),
uuid_string: uuid.String(),
}
return
}
示例10: Get
// Get get build data
func (r *LocalFsRegistry) Get(id uuid.UUID) (schema.Build, error) {
// TODO: add error handling.(Expired Data and Not Found File)
file, err := os.Open(r.dir + id.String() + ".json")
if err != nil {
return schema.Build{}, err
}
defer file.Close()
var build schema.Build
err = json.NewDecoder(file).Decode(&build)
if err != nil {
return schema.Build{}, err
}
return build, nil
}
示例11: Get
func (r *EtcdRegistry) Get(id uuid.UUID) (schema.Build, error) {
key := path.Join(r.keyPrefix, id.String())
res, err := r.etcd.Get(key, false, true)
if err != nil {
return schema.Build{}, err
}
var build schema.Build
err = unmarshal(res.Node.Value, &build)
if err != nil {
if isKeyNotFound(err) {
// TODO (spesnova): return 404 error
return schema.Build{}, err
}
return schema.Build{}, err
}
return build, nil
}
示例12: getTime
//get time.Time form uuid code
func getTime(uucode uuid.UUID) time.Time {
ut, _ := uucode.Time()
s, n := ut.UnixTime()
return time.Unix(s, n)
}