Exemplo n.º 1
0
// assignRelatedUser assign related user to the location.
func assignRelatedUser(location *model.Location) {
	var tempUser model.User
	if db.ORM.Model(&location).Select(config.UserPublicFields).Related(&tempUser).RecordNotFound() {
		log.Warn("user is not found.")
	}
	location.Author = model.PublicUser{User: &tempUser}
}
Exemplo n.º 2
0
// assignRelatedUser assign related user to the article.
func assignRelatedUser(article *model.Article) {
	var tempUser model.User
	if db.ORM.Model(&article).Select(config.UserPublicFields).Related(&tempUser).RecordNotFound() {
		log.Warn("user is not found.")
	}
	article.Author = model.PublicUser{User: &tempUser}
}
Exemplo n.º 3
0
// AssignRelatedUser assign related user of comment.
func AssignRelatedUser(comments []model.Comment) {
	for i, comment := range comments {
		var tempUser model.User
		if db.ORM.Model(&comment).Select(config.UserPublicFields).Related(&tempUser).RecordNotFound() {
			log.Warn("user is not found.")
		}
		comments[i].User = model.PublicUser{User: &tempUser}
	}
}
Exemplo n.º 4
0
// basicUploader is a uploader that uploading files.
func basicUploader() Uploader {
	return func(reader *multipart.Reader) UploadStatus {
		atomic.AddInt32(workingUploader, 1)
		for {
			part, err := reader.NextPart()

			uploadedNow := atomic.AddUint32(uploaded, 1)
			log.Debugf("count %d", uploadedNow)
			if err == io.EOF {
				log.Warn("End of file.")
				break
			}
			if part.FileName() == "" {
				log.Warn("File name is empty.")
				continue
			}
			UploadImageFile(part)
			log.Debug("File uploaded.")
		}
		log.Debug("Iteration done.")
		return UploadStatus(true)
	}
}
Exemplo n.º 5
0
func SendEmail(msg *gomail.Message) (emailError EmailError) {
	c := make(chan EmailError)
	go func() {
		c <- PostOffice(msg, 집배원, Postman, Cartero, Facteur, Yóudìyuán, почтальон, Leterportisto)
	}()
	timeout := time.After(config.EmailTimeout)
	for i := 0; i < 3; i++ {
		select {
		case emailError = <-c:
			workingNow := atomic.AddInt32(workingOfficer, -1)
			log.Debugf("Email sent. Working officer count : %d", workingNow)
			// atomic.StoreUint32(sent, 0)
			return
		case <-timeout:
			// atomic.StoreUint32(sent, 0)
			workingNow := atomic.AddInt32(workingOfficer, -1)
			log.Debugf("Email sent. Working officer count : %d", workingNow)
			log.Warn("Email timed out")
			emailError = errors.New("Email timed out")
			return
		}
	}
	return
}