本文整理匯總了Golang中euphoria/io/heim/proto.Account.PersonalIdentities方法的典型用法代碼示例。如果您正苦於以下問題:Golang Account.PersonalIdentities方法的具體用法?Golang Account.PersonalIdentities怎麽用?Golang Account.PersonalIdentities使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類euphoria/io/heim/proto.Account
的用法示例。
在下文中一共展示了Account.PersonalIdentities方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Send
func (et *EmailTracker) Send(
ctx scope.Context, js jobs.JobService, templater *templates.Templater, deliverer emails.Deliverer,
account proto.Account, templateName string, data interface{}) (
*emails.EmailRef, error) {
// choose a Message-ID
sf, err := snowflake.New()
if err != nil {
return nil, err
}
domain := "heim"
if deliverer != nil {
domain = deliverer.LocalName()
}
msgID := fmt.Sprintf("<%[email protected]%s>", sf, domain)
// choose an address to send to
to := ""
/*
requireVerifiedAddress := true
switch templateName {
case proto.WelcomeEmail, proto.RoomInvitationWelcomeEmail, proto.PasswordResetEmail:
requireVerifiedAddress = false
}
*/
for _, pid := range account.PersonalIdentities() {
if pid.Namespace() == "email" {
/*
if !pid.Verified() && requireVerifiedAddress {
continue
}
*/
to = pid.ID()
break
}
}
if to == "" {
fmt.Printf("no email address to deliver to\n")
return nil, fmt.Errorf("account has no email address to deliver %s to", templateName)
}
// construct the email
ref, err := emails.NewEmail(templater, msgID, to, templateName, data)
if err != nil {
return nil, err
}
ref.AccountID = account.ID()
// get underlying JobQueue so we can add-and-claim in the same transaction as the email insert
abstractQueue, err := js.GetQueue(ctx, jobs.EmailQueue)
if err != nil {
return nil, err
}
jq := abstractQueue.(*JobQueueBinding)
t, err := et.Backend.DbMap.Begin()
if err != nil {
return nil, err
}
// insert job first, so we know what JobID to associate with the email when we insert it
payload := &jobs.EmailJob{
AccountID: account.ID(),
EmailID: ref.ID,
}
job, err := jq.addAndClaim(ctx, t, jobs.EmailJobType, payload, "immediate", jobs.EmailJobOptions...)
if err != nil {
rollback(ctx, t)
return nil, err
}
ref.JobID = job.ID
// insert the email
var email Email
email.FromBackend(ref)
if err := t.Insert(&email); err != nil {
rollback(ctx, t)
return nil, err
}
// finalize and spin off first delivery attempt
if err := t.Commit(); err != nil {
return nil, err
}
child := ctx.Fork()
child.WaitGroup().Add(1)
go job.Exec(child, func(ctx scope.Context) error {
defer ctx.WaitGroup().Done()
logging.Logger(ctx).Printf("delivering to %s\n", to)
if deliverer == nil {
return fmt.Errorf("deliverer not configured")
}
if err := deliverer.Deliver(ctx, ref); err != nil {
return err
}
if _, err := et.Backend.DbMap.Exec("UPDATE email SET delivered = $2 WHERE id = $1", ref.ID, ref.Delivered); err != nil {
// Even if we fail to mark the email as delivered, don't return an
// error so the job still gets completed. We wouldn't want to spam
//.........這裏部分代碼省略.........