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


Golang uuid.NewUUID函數代碼示例

本文整理匯總了Golang中code/google/com/p/go-uuid/uuid.NewUUID函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewUUID函數的具體用法?Golang NewUUID怎麽用?Golang NewUUID使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


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

示例1: SignUpload

func SignUpload(c *gin.Context) {
	user, err := GetUserFromContext(c)

	if err != nil {
		c.Fail(500, err)
	}

	var json UploadJSON
	c.Bind(&json)

	key := `attachments/` + user.Id + `/` + uuid.NewUUID().String() + extensions[json.ContentType]

	f := &Form{
		Key:            key,
		ACL:            "public-read",
		AWSAccessKeyId: os.Getenv("AWS_ACCESS_KEY_ID"),
		CacheControl:   "max-age=31557600",
		ContentType:    json.ContentType,
	}

	f.build()

	href := "https://s3.amazonaws.com/" + os.Getenv("S3_BUCKET") + "/" + key

	c.JSON(200, gin.H{"form": f, "href": href})
}
開發者ID:blarralde,項目名稱:landline-api,代碼行數:26,代碼來源:upload_handler.go

示例2: PostRegister

//POST account/register
func (c Account) PostRegister(user models.User) revel.Result {
	user.Validate(c.Validation)
	if c.Validation.HasErrors() {
		//把錯誤信息存到flash
		c.Validation.Keep()
		//把參數存到flash
		//c.FlashParams()
		return c.Redirect(routes.Account.Register())
	}
	user.GravatarUrl = genGravatarUrl(user.Email)
	code := uuid.NewUUID()
	user.ActiveCode = code.String()
	user.ActiveCodeCreatedTime = time.Now()
	if !user.Save() {
		c.Flash.Error("Registered user failed")
		return c.Redirect(routes.Account.Register())
	}
	c.Session[USERNAME] = user.Name
	subject := "activate password"
	content := fmt.Sprintf(`<h2><a href="http://%s:%s/account/activate/%s">`+
		`activate account</a></h2>`,
		appAddr, appPort, user.ActiveCode)
	err := SendMail(
		subject,
		content,
		smtpConfig.Username,
		[]string{user.Email},
		smtpConfig,
		true)
	if err != nil {
		fmt.Println(err)
	}
	c.Flash.Success("please check email to make your account active")
	return c.Redirect(routes.Account.Notice())
}
開發者ID:jango2015,項目名稱:OJ,代碼行數:36,代碼來源:account.go

示例3: getToken

func getToken(w http.ResponseWriter, req *http.Request) {
	glog.Info("getToken")
	var cred struct {
		Username string
		Password string
	}
	d := json.NewDecoder(req.Body)
	if d == nil {
		w.WriteHeader(http.StatusInternalServerError)
		return
	}
	if err := d.Decode(&cred); err != nil {
		w.WriteHeader(http.StatusBadRequest)
		return
	}
	if cred.Username != "user" || cred.Password != "password" {
		glog.Infof("Bad credentials user: %s, pass: %s", cred.Username, cred.Password)
		w.WriteHeader(http.StatusUnauthorized)
		w.Write(unauthRes)
		return
	}
	token = uuid.NewUUID()
	b, err := json.Marshal(token.String())
	if err != nil {
		w.WriteHeader(http.StatusBadRequest)
		return
	}
	w.Write(b)
}
開發者ID:mattyao1984,項目名稱:angular-oauth,代碼行數:29,代碼來源:main.go

示例4: SendResetEmail

//POST /account/send-reset-email
func (c Account) SendResetEmail(email string) revel.Result {
	var user models.User
	code := uuid.NewUUID()
	user.Email = email
	user.ResetCode = code.String()
	user.ResetCodeCreatedTime = time.Now()
	if user.HasEmail() {
		_, err := engine.Where("email = ?", email).
			Cols("reset_code", "reset_code_created_time").
			Update(&user)
		if err != nil {
			fmt.Println(err)
		}
		subject := "reset password"
		content := fmt.Sprintf(
			`<h2><a href="http://%s:%s/account/reset/%s">Reset Password</a></h2>`,
			appAddr, appPort, user.ResetCode)
		SendMail(
			subject,
			content,
			smtpConfig.Username,
			[]string{email},
			smtpConfig,
			true)
		c.Flash.Success("Email has been sent, pleas check it.")
		return c.Redirect(routes.Account.Notice())
	} else {
		c.Flash.Error("Incorrect Email")
		return c.Redirect(routes.Account.Notice())
	}
}
開發者ID:jango2015,項目名稱:OJ,代碼行數:32,代碼來源:account.go

示例5: SignUp

//注冊
func (u *UserController) SignUp(user models.User) revel.Result {

	user.Validation(u.q, u.Validation)

	if u.Validation.HasErrors() {
		u.Validation.Keep()
		return u.Redirect(routes.UserController.SignUpRedirect())
	}
	notEncrypted := user.Password
	user.Password = models.EncryptPassword(user.Password)
	user.ValidateCode = strings.Replace(uuid.NewUUID().String(), "-", "", -1)
	if !user.Save(u.q) {
		u.Flash.Error("注冊用戶失敗")
		return u.Redirect(routes.UserController.SignUpRedirect())
	}
	subject := "激活賬號 —— 奇享-向世界分享我們"
	content := `這封信是由 奇享 發送的。
				您收到這封郵件,是由於在 奇享 獲取了新用戶注冊地址使用 了這個郵箱地址。如果您並沒有訪問過 奇享,
				或沒有進行上述操作,請忽 略這封郵件。
				您不需要退訂或進行其他進一步的操作。
				----------------------------------------------------------------------
				新用戶注冊說明
				----------------------------------------------------------------------
				如果您是 奇享 的新用戶,或在修改您的注冊 Email 時使用了本地址,我們需 要對您的地址有效性進行驗證以避免垃圾郵件或地址被濫用。
				您隻需點擊下麵的鏈接即可進行用戶注冊,
				"http://localhost:9000/user/validate/` + user.ValidateCode + `"
				(如果上麵不是鏈接形式,請將該地址手工粘貼到瀏覽器地址欄再訪問)
				 感謝您的訪問,祝您使用愉快!`
	//發送驗證郵件
	go sendMail(subject, content, []string{user.Email})
	//注冊成功登陸
	return u.SignIn(user.Email, notEncrypted, "")

}
開發者ID:river-lee,項目名稱:qishare,代碼行數:35,代碼來源:UserController.go

示例6: NewMessage

// New Message will create a new message struct to send to nsq
func (queue *NsqAdapter) NewMessage(topic string, messageType string, payload interface{}) *Message {

	// create a new Message
	message := Message{}

	// set a unique id for our message
	message.Id = uuid.NewUUID().String()

	// set the originating service
	message.From = queue.Name

	// set the message to send the data to
	message.To = topic

	// define the time until we need the response
	message.StartTime = time.Now().String()

	// set the payload
	message.Payload, _ = json.Marshal(payload)

	// set the type
	message.MessageType = messageType

	return &message
}
開發者ID:ibmendoza,項目名稱:nsq-adapter,代碼行數:26,代碼來源:adapter_main.go

示例7: SignupPost

func (c *User) SignupPost(user models.User) revel.Result {
	user.Validate(c.Validation)
	if c.Validation.HasErrors() {
		c.Validation.Keep()
		c.FlashParams()
		return c.Redirect(routes.User.Signup())
	}

	user.Type = MemberGroup
	user.Avatar = defaultAvatar
	user.ValidateCode = strings.Replace(uuid.NewUUID().String(), "-", "", -1)

	if !user.Save() {
		c.Flash.Error("注冊用戶失敗")
		return c.Redirect(routes.User.Signup())
	}

	subject := "激活賬號"
	content := `<h2><a href="http://gorevel.cn/user/validate/` + user.ValidateCode + `">激活賬號</a></h2>`
	go sendMail(subject, content, []string{user.Email})

	c.Flash.Success(fmt.Sprintf("%s 注冊成功,請到您的郵箱 %s 激活賬號!", user.Name, user.Email))

	perm := new(models.Permissions)
	perm.UserId = user.Id
	perm.Perm = MemberGroup
	perm.Save()

	return c.Redirect(routes.User.Signin())
}
開發者ID:jsli,項目名稱:gorevel,代碼行數:30,代碼來源:user.go

示例8: changePasswordHandler

// URL: /user_center/change_password
// 修改密碼
func changePasswordHandler(handler *Handler) {
	user, _ := currentUser(handler)

	form := wtforms.NewForm(
		wtforms.NewPasswordField("current_password", "當前密碼", wtforms.Required{}),
		wtforms.NewPasswordField("new_password", "新密碼", wtforms.Required{}),
		wtforms.NewPasswordField("confirm_password", "新密碼確認", wtforms.Required{}),
	)

	if handler.Request.Method == "POST" && form.Validate(handler.Request) {
		if form.Value("new_password") == form.Value("confirm_password") {
			currentPassword := encryptPassword(form.Value("current_password"), user.Password)
			if currentPassword == user.Password {
				c := handler.DB.C(USERS)
				salt := strings.Replace(uuid.NewUUID().String(), "-", "", -1)
				c.Update(bson.M{"_id": user.Id_}, bson.M{"$set": bson.M{
					"password": encryptPassword(form.Value("new_password"), salt),
					"salt":     salt,
				}})
				message(handler, "密碼修改成功", `密碼修改成功`, "success")
				return
			} else {
				form.AddError("current_password", "當前密碼錯誤")
			}
		} else {
			form.AddError("confirm_password", "密碼不匹配")
		}
	}

	handler.renderTemplate("user_center/change_password.html", BASE, map[string]interface{}{
		"form":   form,
		"active": "change_password",
	})
}
開發者ID:kevinhuo88888,項目名稱:sapnote,代碼行數:36,代碼來源:user_center.go

示例9: Forgot

//忘記密碼
func (u *UserController) Forgot(mail string) revel.Result {
	//重新生成驗證碼
	user := new(models.User)
	user.ValidateCode = strings.Replace(uuid.NewUUID().String(), "-", "", -1)
	user.Email = mail
	_, err := u.q.Update(user)
	if err != nil {
		fmt.Println(err)
	}
	subject := "激活賬號 —— 奇享-向世界分享我們"
	content := `這封信是由 奇享 發送的。
				您收到這封郵件,是由於在 奇享 獲取了新用戶注冊地址使用 了這個郵箱地址。如果您並沒有訪問過 奇享,
				或沒有進行上述操作,請忽 略這封郵件。
				您不需要退訂或進行其他進一步的操作。
				----------------------------------------------------------------------
				找回密碼說明
				----------------------------------------------------------------------
				如果您是 奇享 的老用戶,或在修改您的注冊 Email 時使用了本地址,我們需 要對您的地址有效性進行驗證以避免垃圾郵件或地址被濫用。
				您隻需點擊下麵的鏈接即可進行用戶密碼找回,
				"http://localhost:9000/user/forgot/` + user.ValidateCode + `"
				(如果上麵不是鏈接形式,請將該地址手工粘貼到瀏覽器地址欄再訪問)
				 感謝您的訪問,祝您使用愉快!`
	//發送驗證郵件
	go sendMail(subject, content, []string{user.Email})
	return u.Redirect(routes.UserController.ForgotRedirect())
}
開發者ID:river-lee,項目名稱:qishare,代碼行數:27,代碼來源:UserController.go

示例10: run

func (s *Sidecar) run() {
	parts := strings.Split(s.address, ":")
	host := strings.Join(parts[:len(parts)-1], ":")
	port, _ := strconv.Atoi(parts[len(parts)-1])

	id := s.name + "-" + uuid.NewUUID().String()
	node := &registry.Node{
		Id:      id,
		Address: host,
		Port:    port,
	}

	service := &registry.Service{
		Name:  s.name,
		Nodes: []*registry.Node{node},
	}

	log.Infof("Registering %s", node.Id)
	registry.Register(service)

	if len(s.hcUrl) > 0 {
		log.Info("Starting sidecar healthchecker")
		exitCh := make(chan bool, 1)
		go s.hcLoop(service, exitCh)
		defer func() {
			exitCh <- true
		}()
	}

	ch := make(chan os.Signal, 1)
	signal.Notify(ch, syscall.SIGTERM, syscall.SIGINT, syscall.SIGKILL)
	<-ch
}
開發者ID:Huangyan9188,項目名稱:micro,代碼行數:33,代碼來源:car.go

示例11: GetID

func (setting *ServiceSetting) GetID() string {
	if setting.ID == "" {
		setting.ID = uuid.NewUUID().String()
	}

	return setting.ID
}
開發者ID:haiheipijuan,項目名稱:kasi,代碼行數:7,代碼來源:service.go

示例12: insertTestData

//添加測試內容
func insertTestData() {

	var affects int64
	firstPost := &Post{}
	count, _ := Engine.Count(firstPost)
	if count == 0 {
		firstPost.Slug = strings.Replace(uuid.NewUUID().String(), "-", "", -1)
		firstPost.Title = "Hello world!"
		firstPost.Content = "第一篇測試內容,<strong>Hello world!</strong>"
		firstPost.Tags = "測試"
		firstPost.CommentCount = 0
		firstPost.Created = time.Now()
		affects, _ = Engine.InsertOne(firstPost)

		if affects > 0 && firstPost.Id > 0 {
			firstComment := &Comment{}
			firstComment.PostId = firstPost.Id
			firstComment.Name = "System"
			firstComment.Message = "第一個評論測試"
			firstComment.Created = time.Now()
			affects, _ = Engine.InsertOne(firstComment)
			revel.TRACE.Println("insert first comment affects = ", affects)
			if affects > 0 {
				firstPost.CommentCount = 1
				Engine.Update(firstPost)
			}
		}

	}

}
開發者ID:supermouseno1,項目名稱:blogo,代碼行數:32,代碼來源:init.go

示例13: frameworkReregistered

func (driver *MesosSchedulerDriver) frameworkReregistered(from *upid.UPID, pbMsg proto.Message) {
	log.V(1).Infoln("Handling Scheduler re-registered event.")
	msg := pbMsg.(*mesos.FrameworkReregisteredMessage)

	if driver.Status() == mesos.Status_DRIVER_ABORTED {
		log.Infoln("Ignoring FrameworkReregisteredMessage from master, driver is aborted!")
		return
	}
	if driver.connected {
		log.Infoln("Ignoring FrameworkReregisteredMessage from master,driver is already connected!")
		return
	}
	if !driver.MasterPid.Equal(from) {
		log.Warningf("ignoring framework re-registered message because it was sent from '%v' instead of leading master '%v'", from, driver.MasterPid)
		return
	}

	// TODO(vv) detect if message was from leading-master (sched.cpp)
	log.Infof("Framework re-registered with ID [%s] ", msg.GetFrameworkId().GetValue())
	driver.setConnected(true)
	driver.connection = uuid.NewUUID()

	driver.Scheduler.Reregistered(driver, msg.GetMasterInfo())

}
開發者ID:nagyistoce,項目名稱:ms-docker-swarm,代碼行數:25,代碼來源:scheduler.go

示例14: frameworkRegistered

// ---------------------- Handlers for Events from Master --------------- //
func (driver *MesosSchedulerDriver) frameworkRegistered(from *upid.UPID, pbMsg proto.Message) {
	log.V(2).Infoln("Handling scheduler driver framework registered event.")

	msg := pbMsg.(*mesos.FrameworkRegisteredMessage)
	masterInfo := msg.GetMasterInfo()
	masterPid := masterInfo.GetPid()
	frameworkId := msg.GetFrameworkId()

	if driver.Status() == mesos.Status_DRIVER_ABORTED {
		log.Infof("ignoring FrameworkRegisteredMessage from master %s, driver is aborted", masterPid)
		return
	}

	if driver.connected {
		log.Infoln("ignoring FrameworkRegisteredMessage from master, driver is already connected", masterPid)
		return
	}

	if driver.stopped {
		log.Infof("ignoring FrameworkRegisteredMessage from master %s, driver is stopped", masterPid)
		return
	}
	if !driver.MasterPid.Equal(from) {
		log.Warningf("ignoring framework registered message because it was sent from '%v' instead of leading master '%v'", from, driver.MasterPid)
		return
	}

	log.Infof("Framework registered with ID=%s\n", frameworkId.GetValue())
	driver.FrameworkInfo.Id = frameworkId // generated by master.

	driver.setConnected(true)
	driver.connection = uuid.NewUUID()
	driver.Scheduler.Registered(driver, frameworkId, masterInfo)
}
開發者ID:nagyistoce,項目名稱:ms-docker-swarm,代碼行數:35,代碼來源:scheduler.go

示例15: GetID

func (setting *EndpointSetting) GetID() string {
	if setting.ID == "" {
		setting.ID = uuid.NewUUID().String()
	}

	return setting.ID
}
開發者ID:haiheipijuan,項目名稱:kasi,代碼行數:7,代碼來源:endpoint.go


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