當前位置: 首頁>>代碼示例>>Golang>>正文


Golang uuid.UUID函數代碼示例

本文整理匯總了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
}
開發者ID:kildevaeld,項目名稱:projects,代碼行數:25,代碼來源:intface.go

示例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()
}
開發者ID:2722,項目名稱:lantern,代碼行數:8,代碼來源:buuid.go

示例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
}
開發者ID:LivousCraftNetwork,項目名稱:GoLilyPad,代碼行數:9,代碼來源:types.go

示例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
}
開發者ID:codeaudit,項目名稱:shift,代碼行數:11,代碼來源:key_store_passphrase.go

示例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
}
開發者ID:CedarLogic,項目名稱:go-ethereum,代碼行數:12,代碼來源:key_store_passphrase.go

示例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())
}
開發者ID:chenzhen411,項目名稱:kubernetes,代碼行數:20,代碼來源:executor.go

示例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
}
開發者ID:cloud9-tools,項目名稱:go-cloudfs,代碼行數:22,代碼來源:client.go

示例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
}
開發者ID:Ima8,項目名稱:kubernetes,代碼行數:40,代碼來源:executor.go

示例9: Interface

func (u *UID) Interface() uuid.UUID {
	return uuid.UUID(u[:])
}
開發者ID:netturpin,項目名稱:contrail-go-api,代碼行數:3,代碼來源:uid.go

示例10: encodeUuid

func encodeUuid(e *encodeState, v reflect.Value) {
	e.WriteString("#uuid ")
	e.string(uuid.UUID(v.Bytes()).String())
}
開發者ID:paxan,項目名稱:go-edn,代碼行數:4,代碼來源:encode.go

示例11: String

func (i UUID) String() string {
	return uuid.UUID(i).String()
}
開發者ID:qorio,項目名稱:omni,代碼行數:3,代碼來源:uuid.go

示例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]
}
開發者ID:JeremyOT,項目名稱:gototo,代碼行數:12,代碼來源:zmqworkerconnection.go

示例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 {
//.........這裏部分代碼省略.........
開發者ID:gtfierro,項目名稱:btrdb,代碼行數:101,代碼來源:cpinterface.go

示例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))
					}
//.........這裏部分代碼省略.........
開發者ID:LivousCraftNetwork,項目名稱:GoLilyPad,代碼行數:101,代碼來源:sessionOutBridge.go

示例15: Equals

func Equals(uuid1, uuid2 UUID) bool {
	return uuid.Equal(uuid.UUID(uuid1), uuid.UUID(uuid2))
}
開發者ID:qorio,項目名稱:omni,代碼行數:3,代碼來源:uuid.go


注:本文中的code/google/com/p/go-uuid/uuid.UUID函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。