本文整理汇总了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})
}
示例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())
}
示例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)
}
示例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())
}
}
示例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, "")
}
示例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
}
示例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())
}
示例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",
})
}
示例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())
}
示例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 := ®istry.Node{
Id: id,
Address: host,
Port: port,
}
service := ®istry.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
}
示例11: GetID
func (setting *ServiceSetting) GetID() string {
if setting.ID == "" {
setting.ID = uuid.NewUUID().String()
}
return setting.ID
}
示例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)
}
}
}
}
示例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())
}
示例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)
}
示例15: GetID
func (setting *EndpointSetting) GetID() string {
if setting.ID == "" {
setting.ID = uuid.NewUUID().String()
}
return setting.ID
}