本文整理匯總了Golang中code/google/com/p/go-uuid/uuid.UUID函數的典型用法代碼示例。如果您正苦於以下問題:Golang UUID函數的具體用法?Golang UUID怎麽用?Golang UUID使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了UUID函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: handle_beacon
func (agent *agent_t) handle_beacon() (err error) {
msg, err := agent.udp.RecvMessage(0)
if len(msg[0]) != 16 {
return errors.New("Not a uuid")
}
// If we got a UUID and it's not our own beacon, we have a peer
uuid := uuid.UUID(msg[0])
if bytes.Compare(uuid, agent.uuid_bytes) != 0 {
// Find or create peer via its UUID string
uuid_string := uuid.String()
peer, ok := agent.peers[uuid_string]
if !ok {
peer = new_peer(uuid)
agent.peers[uuid_string] = peer
// Report peer joined the network
agent.pipe.SendMessage("JOINED", uuid_string)
}
// Any activity from the peer means it's alive
peer.is_alive()
}
return
}
示例2: String
// String() returns the string-encoded version like in uuid.UUID.
func (id ID) String() string {
b := uuid.UUID(make([]byte, EncodedLength))
if err := id.Write([]byte(b)); err != nil {
log.Errorf("Unable to write as string: %v", err)
}
return b.String()
}
示例3: ReadUUID
func ReadUUID(reader io.Reader, util []byte) (result uuid.UUID, err error) {
bytes := make([]byte, 16)
_, err = reader.Read(bytes)
if err != nil {
return
}
result = uuid.UUID(bytes)
return
}
示例4: GetKey
func (ks keyStorePassphrase) GetKey(keyAddr common.Address, auth string) (key *Key, err error) {
keyBytes, keyId, err := decryptKeyFromFile(ks.keysDirPath, keyAddr, auth)
if err == nil {
key = &Key{
Id: uuid.UUID(keyId),
Address: keyAddr,
PrivateKey: ToECDSA(keyBytes),
}
}
return
}
示例5: GetKey
func (ks keyStorePassphrase) GetKey(keyAddr []byte, auth string) (key *Key, err error) {
keyBytes, keyId, err := DecryptKey(ks, keyAddr, auth)
if err != nil {
return nil, err
}
key = &Key{
Id: uuid.UUID(keyId),
Address: keyAddr,
PrivateKey: ToECDSA(keyBytes),
}
return key, err
}
示例6: statusUpdateAcknowledgement
func (driver *MesosExecutorDriver) statusUpdateAcknowledgement(from *upid.UPID, pbMsg proto.Message) {
log.Infoln("Executor statusUpdateAcknowledgement")
msg := pbMsg.(*mesosproto.StatusUpdateAcknowledgementMessage)
log.Infof("Receiving status update acknowledgement %v", msg)
frameworkID := msg.GetFrameworkId()
taskID := msg.GetTaskId()
uuid := uuid.UUID(msg.GetUuid())
if driver.stopped {
log.Infof("Ignoring status update acknowledgement %v for task %v of framework %v because the driver is stopped!\n",
uuid, taskID, frameworkID)
}
// Remove the corresponding update.
delete(driver.updates, uuid.String())
// Remove the corresponding task.
delete(driver.tasks, taskID.String())
}
示例7: Stat
func (fs *FileSystem) Stat(ctx context.Context, pathname string, opts ...grpc.CallOption) (*FileStat, error) {
pathname = path.Clean(pathname)
out, err := fs.Interface.Stat(ctx, &StatRequest{Path: pathname}, opts...)
if err != nil {
return nil, &os.PathError{Op: "Stat", Path: pathname, Err: err}
}
return &FileStat{
Inode: uuid.UUID(out.Inode),
Version: out.Version,
Size: out.Size,
Attrs: out.Attr,
Created: fromInodeTime(out.Created),
LastModified: fromInodeTime(out.LastModified),
LastChanged: fromInodeTime(out.LastChanged),
AdminID: out.AdminId,
QuotaID: out.QuotaId,
WriterID: out.WriterId,
ReaderID: out.ReaderId,
IsDirectory: out.IsDirectory,
IsFinal: out.IsFinal,
}, nil
}
示例8: SendStatusUpdate
// SendStatusUpdate sends status updates to the slave.
func (driver *MesosExecutorDriver) SendStatusUpdate(taskStatus *mesosproto.TaskStatus) (mesosproto.Status, error) {
log.V(3).Infoln("Sending task status update: ", taskStatus.String())
if stat := driver.Status(); stat != mesosproto.Status_DRIVER_RUNNING {
return stat, fmt.Errorf("Unable to SendStatusUpdate, expecting driver.status %s, but got %s", mesosproto.Status_DRIVER_RUNNING, stat)
}
if taskStatus.GetState() == mesosproto.TaskState_TASK_STAGING {
err := fmt.Errorf("Executor is not allowed to send TASK_STAGING status update. Aborting!")
log.Errorln(err)
if err0 := driver.stop(mesosproto.Status_DRIVER_ABORTED); err0 != nil {
log.Errorln("Error while stopping the driver", err0)
}
return driver.Status(), err
}
// Set up status update.
update := driver.makeStatusUpdate(taskStatus)
log.Infof("Executor sending status update %v\n", update.String())
// Capture the status update.
driver.lock.Lock()
driver.updates[uuid.UUID(update.GetUuid()).String()] = update
driver.lock.Unlock()
// Put the status update in the message.
message := &mesosproto.StatusUpdateMessage{
Update: update,
Pid: proto.String(driver.self.String()),
}
// Send the message.
if err := driver.send(driver.slaveUPID, message); err != nil {
log.Errorf("Failed to send %v: %v\n", message, err)
return driver.status, err
}
return driver.Status(), nil
}
示例9: Interface
func (u *UID) Interface() uuid.UUID {
return uuid.UUID(u[:])
}
示例10: encodeUuid
func encodeUuid(e *encodeState, v reflect.Value) {
e.WriteString("#uuid ")
e.string(uuid.UUID(v.Bytes()).String())
}
示例11: String
func (i UUID) String() string {
return uuid.UUID(i).String()
}
示例12: handleResponse
func (c *WorkerConnection) handleResponse(response [][]byte) {
key := string(response[1])
c.requestLock.Lock()
request := c.requests[key]
delete(c.requests, key)
c.requestLock.Unlock()
if request == nil {
log.Println("Response received for invalid request - it may have already been answered: ", uuid.UUID(response[1]))
return
}
request.ResponseChan <- response[2]
}
示例13: dispatchCommands
func (c *CPInterface) dispatchCommands(q *btrdb.Quasar, conn net.Conn) {
//This governs the stream
rmtx := sync.Mutex{}
wmtx := sync.Mutex{}
log.Info("cpnp connection")
for !c.isShuttingDown {
rmtx.Lock()
seg, err := capn.ReadFromStream(conn, nil)
if err != nil {
log.Warning("ERR (%v) :: %v", conn.RemoteAddr(), err)
conn.Close()
break
}
rmtx.Unlock()
go func() {
seg := seg
req := ReadRootRequest(seg)
mkresp := func() (Response, *capn.Segment) {
rvseg := capn.NewBuffer(nil)
resp := NewRootResponse(rvseg)
resp.SetEchoTag(req.EchoTag())
return resp, rvseg
}
sendresp := func(seg *capn.Segment) {
wmtx.Lock()
seg.WriteTo(conn)
wmtx.Unlock()
}
switch req.Which() {
case REQUEST_QUERYSTANDARDVALUES:
//log.Info("QSV\n")
st := req.QueryStandardValues().StartTime()
et := req.QueryStandardValues().EndTime()
uuid := uuid.UUID(req.QueryStandardValues().Uuid())
ver := req.QueryStandardValues().Version()
//log.Info("[REQ=QsV] st=%v, et=%v, uuid=%v, gen=%v", st, et, uuid, ver)
if ver == 0 {
ver = btrdb.LatestGeneration
}
recordc, errorc, gen := q.QueryValuesStream(uuid, st, et, ver)
if recordc == nil {
log.Warning("RESPONDING ERR: %v", err)
resp, rvseg := mkresp()
resp.SetStatusCode(STATUSCODE_INTERNALERROR)
resp.SetFinal(true)
sendresp(rvseg)
return
} else {
bufarr := make([]qtree.Record, 0, 4096)
for {
resp, rvseg := mkresp()
fail := false
fin := false
for {
select {
case _, ok := <-errorc:
if ok {
fin = true
fail = true
goto donestandard
}
case r, ok := <-recordc:
if !ok {
fin = true
goto donestandard
}
bufarr = append(bufarr, r)
if len(bufarr) == cap(bufarr) {
goto donestandard
}
}
}
donestandard:
if fail {
resp.SetStatusCode(STATUSCODE_INTERNALERROR)
resp.SetFinal(true)
//consume channels
go func() {
for _ = range recordc {
}
}()
go func() {
for _ = range errorc {
}
}()
sendresp(rvseg)
return
}
records := NewRecords(rvseg)
rl := NewRecordList(rvseg, len(bufarr))
rla := rl.ToArray()
for i, v := range bufarr {
rla[i].SetTime(v.Time)
rla[i].SetValue(v.Val)
}
records.SetVersion(gen)
records.SetValues(rl)
resp.SetRecords(records)
resp.SetStatusCode(STATUSCODE_OK)
if fin {
//.........這裏部分代碼省略.........
示例14: HandlePacket
func (this *SessionOutBridge) HandlePacket(packet packet.Packet) (err error) {
if !this.session.Authenticated() {
this.conn.Close()
return
}
switch this.state {
case STATE_LOGIN:
if packet.Id() == minecraft.PACKET_CLIENT_LOGIN_SUCCESS {
this.session.redirectMutex.Lock()
this.state = STATE_INIT
this.session.redirecting = true
this.EnsureCompression()
if this.session.protocol17 {
this.pipeline.Replace("registry", minecraft.PlayPacketClientCodec17)
} else {
this.pipeline.Replace("registry", minecraft.PlayPacketClientCodec)
}
} else if packet.Id() == minecraft.PACKET_CLIENT_LOGIN_DISCONNECT {
this.session.DisconnectJson(packet.(*minecraft.PacketClientLoginDisconnect).Json)
this.conn.Close()
} else if packet.Id() == minecraft.PACKET_CLIENT_LOGIN_SET_COMPRESSION {
this.SetCompression(packet.(*minecraft.PacketClientLoginSetCompression).Threshold)
} else {
if this.session.Initializing() {
this.session.Disconnect("Error: Outbound Protocol Mismatch")
}
this.conn.Close()
}
case STATE_INIT:
if packet.Id() == minecraft.PACKET_CLIENT_PLAYER_POSITION_AND_LOOK {
this.session.outBridge = this
this.session.redirecting = false
this.session.state = STATE_CONNECTED
this.state = STATE_CONNECTED
this.session.redirectMutex.Unlock()
}
fallthrough
case STATE_CONNECTED:
if packet.Id() == minecraft.PACKET_CLIENT_DISCONNECT {
this.state = STATE_DISCONNECTED
}
if this.state == STATE_CONNECTED {
this.session.redirectMutex.Lock()
if this.session.outBridge != this {
this.session.outBridge.EnsureCompression()
this.conn.Close()
this.session.redirectMutex.Unlock()
break
}
this.session.redirectMutex.Unlock()
}
switch packet.Id() {
case minecraft.PACKET_CLIENT_JOIN_GAME:
joinGamePacket := packet.(*minecraft.PacketClientJoinGame)
if this.session.clientSettings != nil {
this.Write(this.session.clientSettings)
}
this.session.serverEntityId = joinGamePacket.EntityId
if this.session.state == STATE_INIT {
this.session.clientEntityId = joinGamePacket.EntityId
} else {
var swapDimension int32
if joinGamePacket.Dimension == 0 {
swapDimension = 1
} else {
swapDimension = 0
}
this.session.Write(minecraft.NewPacketClientRespawn(swapDimension, 2, 0, "DEFAULT"))
this.session.Write(minecraft.NewPacketClientRespawn(int32(joinGamePacket.Dimension), joinGamePacket.Difficulty, joinGamePacket.Gamemode, joinGamePacket.LevelType))
if len(this.session.playerList) > 0 {
if this.session.protocol17 {
for player, _ := range this.session.playerList {
this.session.Write(minecraft.NewPacketClientPlayerList17Remove(player))
}
} else {
items := make([]minecraft.PacketClientPlayerListItem, 0, len(this.session.playerList))
for uuidString, _ := range this.session.playerList {
items = append(items, minecraft.PacketClientPlayerListItem{UUID: uuid.UUID(uuidString)})
}
this.session.Write(minecraft.NewPacketClientPlayerList(minecraft.PACKET_CLIENT_PLAYER_LIST_ACTION_REMOVE, items))
}
this.session.playerList = make(map[string]struct{})
}
if len(this.session.scoreboards) > 0 {
for scoreboard, _ := range this.session.scoreboards {
this.session.Write(minecraft.NewPacketClientScoreboardObjectiveRemove(scoreboard))
}
this.session.scoreboards = make(map[string]struct{})
}
if len(this.session.teams) > 0 {
for team, _ := range this.session.teams {
this.session.Write(minecraft.NewPacketClientTeamsRemove(team))
}
this.session.teams = make(map[string]struct{})
}
if len(this.session.pluginChannels) > 0 {
channels := make([][]byte, 0, len(this.session.pluginChannels))
for channel, _ := range this.session.pluginChannels {
channels = append(channels, []byte(channel))
}
//.........這裏部分代碼省略.........
示例15: Equals
func Equals(uuid1, uuid2 UUID) bool {
return uuid.Equal(uuid.UUID(uuid1), uuid.UUID(uuid2))
}