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


Golang UUID.String方法代碼示例

本文整理匯總了Golang中github.com/nu7hatch/gouuid.UUID.String方法的典型用法代碼示例。如果您正苦於以下問題:Golang UUID.String方法的具體用法?Golang UUID.String怎麽用?Golang UUID.String使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/nu7hatch/gouuid.UUID的用法示例。


在下文中一共展示了UUID.String方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: SaveSession

// Save to DB
func (this *UdpSessionList) SaveSession(sid *uuid.UUID, s *UdpSession) error {
	v, ok := gUdpSessions.udpmap[s.Addr.String()]
	if ok {
		v.Reset(40 * time.Second)
	}
	return SetDeviceSession(sid.String(), gUdpTimeout, s.String(), s.DeviceId, s.Addr)
}
開發者ID:ljvblfz,項目名稱:slot-golang,代碼行數:8,代碼來源:udp_session.go

示例2: NewJob

/*
NewJob creates a new job from the config as well as a job spec.  After creating
the job, calling job.Process() will actually perform the work.
*/
func NewJob(cfg *Config, spec *Spec, req *http.Request) *Job {
	var idUUID *gouuid.UUID
	var err error
	idUUID, err = gouuid.NewV4()
	if TestMode {
		idUUID, err = gouuid.NewV5(gouuid.NamespaceURL, []byte("0"))
	}

	if err != nil {
		cfg.Logger.WithField("error", err).Error("error creating uuid")
	}
	id := idUUID.String()

	bobfile := spec.Bobfile
	if bobfile == "" {
		bobfile = defaultBobfile
	}

	ret := &Job{
		Bobfile:        bobfile,
		ID:             id,
		Account:        spec.RepoOwner,
		GitHubAPIToken: spec.GitHubAPIToken,
		Ref:            spec.GitRef,
		Repo:           spec.RepoName,
		Workdir:        cfg.Workdir,
		InfoRoute:      "/jobs/" + id,
		LogRoute:       "/jobs/" + id + "/tail?n=" + defaultTail,
		logDir:         cfg.Workdir + "/" + id,
		Status:         "created",
		Created:        time.Now(),
	}
	ret.addHostToRoutes(req)

	out, file, err := newMultiWriter(ret.logDir)
	if err != nil {
		cfg.Logger.WithField("error", err).Error("error creating log dir")
		id = ""
	}

	ret.logFile = file
	ret.Logger = &logrus.Logger{
		Formatter: cfg.Logger.Formatter,
		Level:     cfg.Logger.Level,
		Out:       out,
	}

	if ret.GitHubAPIToken == "" {
		ret.GitHubAPIToken = cfg.GitHubAPIToken
	}

	if id != "" {
		jobs[id] = ret
	}

	return ret
}
開發者ID:carriercomm,項目名稱:docker-builder,代碼行數:61,代碼來源:job.go

示例3: GetSession

// Get existed session from DB
func (this *UdpSessionList) GetSession(sid *uuid.UUID) (*UdpSession, error) {
	data, err := GetDeviceSession(sid.String())
	if err != nil {
		return nil, err
	}
	s := &UdpSession{
		Addr: &net.UDPAddr{},
	}
	err = s.FromString(data)
	if err != nil {
		return nil, err
	}
	s.Sid = sid.String()
	return s, nil
}
開發者ID:ljvblfz,項目名稱:slot-golang,代碼行數:16,代碼來源:udp_session.go

示例4: InsertSession

func (sr *SessionDbRow) InsertSession() (csi *ClearSessionId, err error) {

	var u4 *uuid.UUID

	u4, err = uuid.NewV4()
	if err != nil {
		return nil, err
	}

	csi = new(ClearSessionId)

	saltBytes := makeSalt()
	csi.Salt = hex.EncodeToString(saltBytes)
	csi.SessionToken = u4.String()

	sessionIdCrypt, err := csi.EncryptToken()
	if err != nil {
		err = fmt.Errorf("Failed to encrypt SessionToken: %s", err)
		return nil, err
	}

	insertSql := fmt.Sprintf(`
    INSERT INTO session.session (
        SessionId,
        SysUserId,
        start_dt,
        expires_dt,
        IpAddr,
        UserAgent)
     VALUES ($1, $2, now(), now() + interval '%d second', $3, $4)`, Conf.SessionTimeout)

	_, err = Conf.DatabaseHandle.Exec(insertSql, sessionIdCrypt, sr.SysUserId,
		sr.IpAddr, sr.UserAgent)

	if err != nil {
		glog.Errorf("Insert of session row failed: %s", err)
		return nil, err
	}

	return csi, nil
}
開發者ID:Grant-Murray,項目名稱:session,代碼行數:41,代碼來源:session_model.go

示例5:

		It("should use an empty request ID if generating a new one fails", func() {
			instrumented_handler.GenerateUuid = func() (u *uuid.UUID, err error) {
				return nil, errors.New("test error")
			}
			h.ServeHTTP(httptest.NewRecorder(), req)
			Expect(req.Header.Get("X-CF-RequestID")).To(Equal("00000000-0000-0000-0000-000000000000"))
		})
	})

	Describe("event emission", func() {
		var requestId *uuid.UUID

		BeforeEach(func() {
			requestId, _ = uuid.NewV4()
			req.Header.Set("X-CF-RequestID", requestId.String())
		})

		Context("without an application ID or instanceIndex", func() {
			BeforeEach(func() {
				h.ServeHTTP(httptest.NewRecorder(), req)
			})

			It("should emit a start event with the right origin", func() {
				Expect(fakeEmitter.GetMessages()[0].Event).To(BeAssignableToTypeOf(new(events.HttpStart)))
				Expect(fakeEmitter.GetMessages()[0].Origin).To(Equal("testHandler/41"))
			})

			It("should emit a stop event", func() {
				Expect(fakeEmitter.GetMessages()[1].Event).To(BeAssignableToTypeOf(new(events.HttpStop)))
				stopEvent := fakeEmitter.GetMessages()[1].Event.(*events.HttpStop)
開發者ID:davidwadden,項目名稱:lattice-release,代碼行數:30,代碼來源:instrumented_handler_test.go

示例6:

					UserAgent:     proto.String("our-testing-client"),
				}

				startEvent := factories.NewHttpStart(req, events.PeerType_Server, requestId)

				Expect(startEvent.GetTimestamp()).ToNot(BeZero())
				startEvent.Timestamp = nil

				Expect(startEvent).To(Equal(expectedStartEvent))
			})
		})

		Context("with an application ID", func() {
			It("should include it in the start event", func() {
				applicationId, _ := uuid.NewV4()
				req.Header.Set("X-CF-ApplicationID", applicationId.String())

				startEvent := factories.NewHttpStart(req, events.PeerType_Server, requestId)

				Expect(startEvent.GetApplicationId()).To(Equal(factories.NewUUID(applicationId)))
			})
		})

		Context("with an application instance index", func() {
			It("should include it in the start event", func() {
				req.Header.Set("X-CF-InstanceIndex", "1")

				startEvent := factories.NewHttpStart(req, events.PeerType_Server, requestId)

				Expect(startEvent.GetInstanceIndex()).To(BeNumerically("==", 1))
			})
開發者ID:tomzhang,項目名稱:golang-devops-stuff,代碼行數:31,代碼來源:factories_test.go

示例7:

		})
	})

	Context("event emission", func() {
		It("should emit a start event", func() {
			rt.RoundTrip(req)
			Expect(fakeEmitter.Messages[0].Event).To(BeAssignableToTypeOf(new(events.HttpStart)))
			Expect(fakeEmitter.Messages[0].Origin).To(Equal("testRoundtripper/42"))
		})

		Context("if request ID already exists", func() {
			var existingRequestId *uuid.UUID

			BeforeEach(func() {
				existingRequestId, _ = uuid.NewV4()
				req.Header.Set("X-CF-RequestID", existingRequestId.String())
			})

			It("should emit the existing request ID as the parent request ID", func() {
				rt.RoundTrip(req)
				startEvent := fakeEmitter.Messages[0].Event.(*events.HttpStart)
				Expect(startEvent.GetParentRequestId()).To(Equal(factories.NewUUID(existingRequestId)))
			})
		})

		Context("if round tripper returns an error", func() {
			It("should emit a stop event with blank response fields", func() {
				fakeRoundTripper.FakeError = errors.New("fakeEmitter error")
				rt.RoundTrip(req)

				Expect(fakeEmitter.Messages[1].Event).To(BeAssignableToTypeOf(new(events.HttpStop)))
開發者ID:johannespetzold,項目名稱:gorouter,代碼行數:31,代碼來源:instrumented_round_tripper_test.go

示例8: handle

func (h *Handler) handle(t *UdpMsg) error {
	// TODO need decryption later

	mlen := len(t.Msg)
	if mlen < FrameHeaderLen {
		return fmt.Errorf("[protocol] invalid message length for device proxy,reason: mlen < FrameHeaderLen | %v < %v.", mlen, FrameHeaderLen)
	}
	// check opcode
	op := (0x7 & t.Msg[0])
	if op != 0x2 && op != 0x3 {
		return fmt.Errorf("[protocol] reason: wrong opcode, op!=2&&op!=3, op=", op)
	}

	if op == 0x2 {
		if mlen < FrameHeaderLen+DataHeaderLen {
			return fmt.Errorf("[protocol] invalid message length for protocol,  mlen < FrameHeaderLen+DataHeaderLen ,%v < %v", mlen, FrameHeaderLen+DataHeaderLen)
		}
		packNum := binary.LittleEndian.Uint16(t.Msg[2:4])
		bodyLen := int(binary.LittleEndian.Uint16(t.Msg[FrameHeaderLen+6:]))
		// discard msg if found checking error
		if t.Msg[FrameHeaderLen+8] != msgs.ChecksumHeader(t.Msg, FrameHeaderLen+8) {
			return fmt.Errorf("checksum header error %v!=%v", t.Msg[FrameHeaderLen+8], msgs.ChecksumHeader(t.Msg, FrameHeaderLen+8))
		}

		// check body
		if t.Msg[FrameHeaderLen+9] != msgs.ChecksumHeader(t.Msg[FrameHeaderLen+10:], 2+bodyLen) {
			return fmt.Errorf("checksum body error %v!=%v", t.Msg[FrameHeaderLen+9], msgs.ChecksumHeader(t.Msg[FrameHeaderLen+10:], 2+bodyLen))
		}

		var (
			sess      *UdpSession
			sid       *uuid.UUID
			err       error
			locker    Locker
			body      []byte
			bodyIndex int
		)

		bodyIndex = FrameHeaderLen + DataHeaderLen
		if bodyLen != len(t.Msg[bodyIndex:]) {
			return fmt.Errorf("wrong body length in data header: %d != %d", bodyLen, len(t.Msg[bodyIndex:]))
		}
		body = t.Msg[bodyIndex : bodyIndex+bodyLen]

		// parse data(udp)
		// 28 = FrameHeaderLen + 4
		c := binary.LittleEndian.Uint16(t.Msg[28:30])
		if c == CmdSyncState {
			glog.Infoln("執行設備狀態同步")
			GMsgBusManager.Push2Bus(0, nil, t.Msg)
			return nil
		} else if c == 0x31 {
			glog.Infoln("執行報警信息同步")
			GMsgBusManager.Push2Bus(0, nil, t.Msg)
			return nil
			//TODO alarm msg synchronization
		} else if c != CmdGetToken {
			sid, err = uuid.Parse(t.Msg[bodyIndex : bodyIndex+16])
			if err != nil {
				return fmt.Errorf("parse session id error: %v", err)
			}

			locker = NewDeviceSessionLocker(sid.String())
			err = locker.Lock()
			if err != nil {
				return fmt.Errorf("lock session id [%s] failed: %v", sid, err)
			}
			sess, err = gUdpSessions.GetSession(sid)
			if err != nil {
				locker.Unlock()
				return fmt.Errorf("cmd: %X, sid: [%v], error: %v", c, sid, err)
			}
			err = sess.VerifySession(packNum)
			if err != nil {
				locker.Unlock()
				return fmt.Errorf("cmd: %X, verify session error: %v", c, err)
			}
		}

		output := make([]byte, bodyIndex)
		// copy same packNum into this ACK response
		copy(output[:bodyIndex], t.Msg[:bodyIndex])

		var res []byte
		switch c {
		case CmdGetToken:
			t.CmdType = c
			res, err = h.onGetToken(t, body)

		case CmdRegister:
			t.CmdType = c
			t.Url = h.kApiUrls[c]
			res, err = h.onRegister(t, sess, body)

		case CmdLogin:
			t.CmdType = c
			t.Url = h.kApiUrls[c]
			res, err = h.onLogin(t, sess, body)

		case CmdRename:
//.........這裏部分代碼省略.........
開發者ID:ljvblfz,項目名稱:slot-golang,代碼行數:101,代碼來源:udp_handler.go


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