本文整理汇总了Golang中SpottedRethink/api/helpers.PrintLog函数的典型用法代码示例。如果您正苦于以下问题:Golang PrintLog函数的具体用法?Golang PrintLog怎么用?Golang PrintLog使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PrintLog函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: createPlace
func (place *Place) createPlace(request *restful.Request, response *restful.Response) {
place.Lat = 0
place.Lng = 0
place.PostNb = 0
place.ValidatedAt = *new(time.Time)
place.Validated = false
place.CreateAt = time.Now()
place.UserId = place.user.Id
place.Id = *new(string)
request.Request.ParseMultipartForm(32 << 20)
mpf, hdr, _ := request.Request.FormFile("image")
ext := filepath.Ext(hdr.Filename)
if helpers.CheckFileExtension(ext) == false {
errors := api.Error{}
errors.ListErrors = append(errors.ListErrors, "Only .jpg, .jpeg or .png are authorized.")
response.WriteHeaderAndEntity(406, errors)
helpers.PrintLog(request, response, place.user.Name)
return
}
place.Image = helpers.GenerateHash(50) + ext
go helpers.PutFile("assets/Images/"+place.Image, mpf)
resp, err := r.Table("places").Insert(place).RunWrite(api.Sess)
if err != nil {
response.WriteHeaderAndEntity(http.StatusConflict, err.Error())
return
}
place.Id = resp.GeneratedKeys[0]
response.WriteHeaderAndEntity(http.StatusCreated, place)
helpers.PrintLog(request, response, place.user.Name)
}
示例2: createMessageWithContent
func (message *Message) createMessageWithContent(request *restful.Request, response *restful.Response) {
msg := new(Message)
msg.Content = message.Content
msg.CreatedAt = time.Now()
msg.FromUserId = message.user.Id
msg.TalkId = message.talk.Id
msg.Read = false
if message.talk.UserIdX == message.user.Id {
msg.ToUserId = message.talk.UserIdY
} else {
msg.ToUserId = message.talk.UserIdX
}
resp, err := r.Table("messages").Insert(msg).RunWrite(api.Sess)
if err != nil {
helpers.PrintLog(request, response, message.user.Name)
response.WriteHeaderAndEntity(http.StatusConflict, err.Error())
return
}
msg.Id = resp.GeneratedKeys[0]
message.talk.UpdateLastMessageDate(message.user.Id, message.Content)
response.WriteHeaderAndEntity(http.StatusCreated, msg)
helpers.PrintLog(request, response, message.user.Name)
}
示例3: createMatch
func (match *Match) createMatch(request *restful.Request, response *restful.Response) {
newMatch := new(Match)
newMatch.CreateAt = time.Now()
newMatch.PlaceId = match.post.PlaceId
newMatch.PostId = match.post.Id
newMatch.UserIdX = match.user.Id
newMatch.UserImageX = match.user.UrlPicture
newMatch.UserNameX = match.user.Name
newMatch.UserIdY = match.post.UserId
newMatch.UserNameY = match.post.UserName
newMatch.Validated = false
resp, err := r.Table("matchs").Insert(newMatch).RunWrite(api.Sess)
if err != nil {
response.WriteHeaderAndEntity(http.StatusConflict, err.Error())
helpers.PrintLog(request, response, match.user.Name)
return
}
go func() {
notif := notification.SetMatchReceive()
notif.UserId = match.post.UserId
notif.UserIdFrom = match.user.Id
notif.IdThing = resp.GeneratedKeys[0]
notif.Name = match.user.Name
notif.IdLink = match.post.Id
notif.CreateNotification()
}()
newMatch.Id = resp.GeneratedKeys[0]
response.WriteHeaderAndEntity(http.StatusCreated, newMatch)
helpers.PrintLog(request, response, match.user.Name)
}
示例4: checkBodyCreate
func (user *User) checkBodyCreate(request *restful.Request, response *restful.Response, chain *restful.FilterChain) {
private := UserCreate{}
errors := api.Error{}
err := request.ReadEntity(&private)
if err != nil {
response.AddHeader("Content-Type", "text/plain")
response.WriteErrorString(http.StatusInternalServerError, err.Error())
helpers.PrintLog(request, response, user.Name)
return
}
user.Email = strings.TrimSpace(private.Email)
user.Name = helpers.RemoveManySpaces(helpers.MakeFirstUpperCase(strings.ToLower(private.Name)))
if user.isTwoPasswordAreIdentical(private.Password, private.Password2) == false {
errors.ListErrors = append(errors.ListErrors, "Two passwords aren't identical")
response.WriteHeaderAndEntity(http.StatusNotAcceptable, errors)
helpers.PrintLog(request, response, user.Name)
return
}
if len(private.Password) < 6 {
errors.ListErrors = append(errors.ListErrors, "Your password must contain at least 6 characters")
response.WriteHeaderAndEntity(http.StatusNotAcceptable, errors)
helpers.PrintLog(request, response, user.Name)
return
}
user.Password = private.Password
chain.ProcessFilter(request, response)
}
示例5: createLike
func (like *Like) createLike(request *restful.Request, response *restful.Response) {
newLike := new(Like)
newLike.PostId = like.post.Id
newLike.UserId = like.user.Id
newLike.Created = time.Now()
if err := like.post.UpdateLikeNb(1); err != nil {
response.WriteHeaderAndEntity(http.StatusConflict, err.Error())
return
}
resp, err := r.Table("likes").Insert(newLike).RunWrite(api.Sess)
if err != nil {
like.post.UpdateLikeNb(-1)
response.WriteHeaderAndEntity(http.StatusConflict, err.Error())
helpers.PrintLog(request, response, like.user.Name)
return
}
if like.post.UserId != like.user.Id {
go func() {
notif := notification.SetLikeReceive()
notif.UserId = like.post.UserId
notif.UserIdFrom = like.user.Id
notif.IdThing = resp.GeneratedKeys[0]
notif.Name = like.user.Name
notif.IdLink = like.post.Id
notif.CreateNotification()
}()
}
newLike.Id = resp.GeneratedKeys[0]
response.WriteHeaderAndEntity(http.StatusCreated, newLike)
helpers.PrintLog(request, response, like.user.Name)
}
示例6: updatePostWithImage
func (post *Post) updatePostWithImage(request *restful.Request, response *restful.Response) {
request.Request.ParseMultipartForm(32 << 20)
mpf, hdr, _ := request.Request.FormFile("image")
ext := filepath.Ext(hdr.Filename)
if helpers.CheckFileExtension(ext) == false {
errors := api.Error{}
errors.ListErrors = append(errors.ListErrors, "Only .jpg, .jpeg or .png are authorized.")
response.WriteHeaderAndEntity(406, errors)
helpers.PrintLog(request, response, post.user.Name)
return
}
if strings.Compare(post.Image, "") != 0 {
helpers.RemoveFile("./assets/Images/" + post.Image)
}
post.Image = helpers.GenerateHash(50) + ext
go helpers.PutFile("assets/Images/"+post.Image, mpf)
_, err := r.Table("posts").Get(post.Id).Update(post).RunWrite(api.Sess)
if err != nil {
response.WriteHeaderAndEntity(http.StatusConflict, err.Error())
helpers.PrintLog(request, response, post.user.Name)
return
}
response.WriteHeaderAndEntity(http.StatusOK, post)
helpers.PrintLog(request, response, post.user.Name)
}
示例7: deleteLike
func (like *Like) deleteLike(request *restful.Request, response *restful.Response) {
like.post.Id = like.PostId
if like.post.GetPostById() == false {
response.WriteHeader(http.StatusInternalServerError)
helpers.PrintLog(request, response, like.user.Name)
return
}
if err := like.post.UpdateLikeNb(-1); err != nil {
response.WriteHeaderAndEntity(http.StatusConflict, err.Error())
helpers.PrintLog(request, response, like.user.Name)
return
}
_, err := r.Table("likes").Get(like.Id).Delete().Run(api.Sess)
if err != nil {
response.WriteHeaderAndEntity(http.StatusConflict, err.Error())
helpers.PrintLog(request, response, like.user.Name)
return
}
go func() {
notif := notification.SetLikeReceive()
notif.IdThing = like.Id
notif.UserIdFrom = like.user.Id
notif.RemoveNotification()
}()
response.WriteHeader(http.StatusOK)
helpers.PrintLog(request, response, like.user.Name)
}
示例8: acceptPost
func (post *Post) acceptPost(request *restful.Request, response *restful.Response) {
post.Validated = true
post.ValidatedAt = time.Now()
if err := post.place.IncrementPostNb(); err != nil {
response.WriteHeaderAndEntity(http.StatusInternalServerError, err.Error())
helpers.PrintLog(request, response, post.user.Name)
return
}
post.IdByPlace = post.place.PostNb
_, err := r.Table("posts").Get(post.Id).Update(post).RunWrite(api.Sess)
if err != nil {
response.WriteHeaderAndEntity(http.StatusInternalServerError, err.Error())
helpers.PrintLog(request, response, post.user.Name)
return
}
go func() {
notif := notification.SetPostAccepted()
notif.UserId = post.UserId
notif.UserIdFrom = post.user.Id
notif.IdThing = post.Id
notif.Name = post.PlaceName
notif.IdLink = post.Id
notif.CreateNotification()
}()
response.WriteHeaderAndEntity(http.StatusOK, post)
helpers.PrintLog(request, response, post.user.Name)
}
示例9: refusePost
func (post *Post) refusePost(request *restful.Request, response *restful.Response) {
_, err := r.Table("posts").Get(post.Id).Delete().Run(api.Sess)
if err != nil {
response.WriteHeaderAndEntity(http.StatusInternalServerError, err.Error())
helpers.PrintLog(request, response, post.user.Name)
return
}
if post.Image != "" {
helpers.RemoveFile("./assets/Images/" + post.Image)
}
if post.user.IsUserIsAdmin() == true {
go func() {
notif := notification.SetPostRefused()
notif.UserId = post.UserId
notif.UserIdFrom = post.user.Id
notif.IdThing = post.Id
notif.Name = post.PlaceName
notif.IdLink = post.Id
notif.CreateNotification()
}()
}
response.WriteHeader(http.StatusOK)
helpers.PrintLog(request, response, post.user.Name)
}
示例10: deleteTalk
func (talk *Talk) deleteTalk(request *restful.Request, response *restful.Response) {
_, err := r.Table("talks").Get(talk.Id).Delete().Run(api.Sess)
if err != nil {
response.WriteHeaderAndEntity(http.StatusConflict, err.Error())
helpers.PrintLog(request, response, talk.user.Name)
return
}
response.WriteHeader(http.StatusOK)
helpers.PrintLog(request, response, talk.user.Name)
}
示例11: updatePost
func (post *Post) updatePost(request *restful.Request, response *restful.Response) {
_, err := r.Table("posts").Get(post.Id).Update(post).RunWrite(api.Sess)
if err != nil {
response.WriteHeaderAndEntity(http.StatusInternalServerError, err.Error())
helpers.PrintLog(request, response, post.user.Name)
return
}
response.WriteHeaderAndEntity(http.StatusOK, post)
helpers.PrintLog(request, response, post.user.Name)
}
示例12: createUserFacebook
func (user *User) createUserFacebook(request *restful.Request, response *restful.Response) {
if user.getUserFacebookWithAccessToken(request.HeaderParameter("facebooktoken")) == false {
response.InternalServerError()
helpers.PrintLog(request, response, user.Name)
return
}
newUser := new(User)
//Facebook's data
newUser.FacebookId = user.FacebookId
newUser.UrlPicture = user.UrlPicture
newUser.Name = user.Name
isUserExist := newUser.getUserByFacebookId()
if isUserExist == false {
//user
newUser.Group = 0
newUser.CreateDate = time.Now()
newUser.Email = ""
newUser.Banish = false
}
//Session
newUser.CreateDateToken = time.Now()
newUser.ExpireDateToken = time.Now().AddDate(0, 0, 15)
newUser.Token = uuid.New()
var resp r.WriteResponse
var err error
//insert
if isUserExist == false {
resp, err = r.Table("users").Insert(newUser).RunWrite(api.Sess)
//update
} else {
_, err = r.Table("users").Get(newUser.Id).Update(newUser).RunWrite(api.Sess)
}
if err != nil {
response.WriteHeaderAndEntity(http.StatusConflict, err.Error())
helpers.PrintLog(request, response, user.Name)
return
}
//if user has been insert, we got ID
if isUserExist == false {
newUser.Id = resp.GeneratedKeys[0]
}
response.WriteHeaderAndEntity(http.StatusCreated, newUser)
helpers.PrintLog(request, response, user.Name)
return
}
示例13: IsEmailExist
func (user *User) IsEmailExist(request *restful.Request, response *restful.Response) {
user.Email = strings.TrimSpace(request.HeaderParameter("email"))
if !helpers.IsAConformEmail(user.Email) {
response.WriteHeader(http.StatusNotAcceptable)
helpers.PrintLog(request, response, user.Name)
return
}
if user.GetUserByEmail() == false {
response.WriteHeader(http.StatusNotFound)
} else {
response.WriteHeader(http.StatusOK)
}
helpers.PrintLog(request, response, user.Name)
}
示例14: createUser
func (user *User) createUser(request *restful.Request, response *restful.Response) {
newUser := new(User)
//user
newUser.Email = user.Email
newUser.Name = user.Name
newUser.CreateDate = time.Now()
newUser.Group = 100
newUser.FacebookId = ""
newUser.UrlPicture = ""
newUser.Banish = false
//encrypt password
newUser.Password = helpers.NewCryptPasswd([]byte(user.Password))
//session
newUser.CreateDateToken = time.Now()
newUser.ExpireDateToken = time.Now().AddDate(0, 0, 15)
newUser.Token = uuid.New()
resp, err := r.Table("users").Insert(newUser).RunWrite(api.Sess)
if err != nil {
response.WriteHeaderAndEntity(http.StatusConflict, err.Error())
helpers.PrintLog(request, response, user.Name)
return
}
newUser.Id = resp.GeneratedKeys[0]
newUser.Password = ""
response.WriteHeaderAndEntity(http.StatusCreated, newUser)
}
示例15: acceptPlace
func (place *Place) acceptPlace(request *restful.Request, response *restful.Response) {
if place.getGeolocation() == false {
errors := api.Error{}
errors.ListErrors = append(errors.ListErrors, "We were unable to geolocate your plate")
response.WriteHeaderAndEntity(500, errors)
return
}
place.ValidatedAt = time.Now()
place.Validated = true
_, err := r.Table("places").Get(place.Id).Update(place).RunWrite(api.Sess)
if err != nil {
response.WriteHeaderAndEntity(http.StatusConflict, err.Error())
return
}
go func() {
notif := notification.SetPlaceAccepted()
notif.UserId = place.UserId
notif.UserIdFrom = place.user.Id
notif.IdThing = place.Id
notif.Name = place.Name
notif.IdLink = place.Id
notif.CreateNotification()
}()
response.WriteHeaderAndEntity(http.StatusOK, place)
helpers.PrintLog(request, response, place.user.Name)
}