本文整理匯總了Golang中github.com/ovh/tat/models.Message.Insert方法的典型用法代碼示例。如果您正苦於以下問題:Golang Message.Insert方法的具體用法?Golang Message.Insert怎麽用?Golang Message.Insert使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/ovh/tat/models.Message
的用法示例。
在下文中一共展示了Message.Insert方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Create
// Create a new message on one topic
func (m *MessagesController) Create(ctx *gin.Context) {
messageIn, messageReference, topic, e := m.preCheckTopic(ctx)
if e != nil {
return
}
user, e := PreCheckUser(ctx)
if e != nil {
return
}
isRw := topic.IsUserRW(&user)
if !isRw {
ctx.JSON(http.StatusForbidden, gin.H{"error": fmt.Sprintf("No RW Access to topic " + messageIn.Topic)})
return
}
var message = models.Message{}
info := ""
if messageIn.Action == "bookmark" {
var originalUser = models.User{}
err := originalUser.FindByUsername(utils.GetCtxUsername(ctx))
if err != nil {
ctx.AbortWithError(http.StatusInternalServerError, errors.New("Error while fetching original user."))
return
}
err = message.Insert(originalUser, topic, messageReference.Text, "", -1)
if err != nil {
log.Errorf("Error while InsertMessage with action %s : %s", messageIn.Action, err)
ctx.AbortWithError(http.StatusInternalServerError, errors.New(err.Error()))
return
}
info = fmt.Sprintf("New Bookmark created in %s", topic.Topic)
} else {
err := message.Insert(user, topic, messageIn.Text, messageIn.IDReference, messageIn.DateCreation)
if err != nil {
log.Errorf("Error while InsertMessage %s", err)
ctx.AbortWithError(http.StatusInternalServerError, errors.New(err.Error()))
return
}
go models.WSMessageNew(&models.WSMessageNewJSON{Topic: topic.Topic})
info = fmt.Sprintf("Message created in %s", topic.Topic)
}
out := &messageJSONOut{Message: message, Info: info}
go models.WSMessage(&models.WSMessageJSON{Action: "create", Username: user.Username, Message: message})
ctx.JSON(http.StatusCreated, out)
}