本文整理匯總了Golang中github.com/ovh/tat/models.Topic.Insert方法的典型用法代碼示例。如果您正苦於以下問題:Golang Topic.Insert方法的具體用法?Golang Topic.Insert怎麽用?Golang Topic.Insert使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/ovh/tat/models.Topic
的用法示例。
在下文中一共展示了Topic.Insert方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: insertTopicDM
func (*MessagesController) insertTopicDM(userFrom, userTo models.User) (models.Topic, error) {
var topic = models.Topic{}
topicName := "/Private/" + userFrom.Username + "/DM/" + userTo.Username
topic.Topic = topicName
topic.Description = userTo.Fullname
err := topic.Insert(&userFrom)
if err != nil {
log.Errorf("Error while InsertTopic %s", err)
return topic, err
}
return topic, nil
}
示例2: checkTopicParentDM
func (*MessagesController) checkTopicParentDM(user models.User) error {
topicName := "/Private/" + user.Username + "/DM"
var topicParent = models.Topic{}
err := topicParent.FindByTopic(topicName, false)
if err != nil {
topicParent.Topic = topicName
topicParent.Description = "DM Topics"
err = topicParent.Insert(&user)
if err != nil {
log.Errorf("Error while InsertTopic Parent %s", err)
return err
}
}
return nil
}
示例3: Create
// Create creates a new topic
func (*TopicsController) Create(ctx *gin.Context) {
var topicIn topicCreateJSON
ctx.Bind(&topicIn)
var user = models.User{}
err := user.FindByUsername(utils.GetCtxUsername(ctx))
if err != nil {
ctx.JSON(http.StatusInternalServerError, gin.H{"error": "Error while fetching user."})
return
}
var topic models.Topic
topic.Topic = topicIn.Topic
topic.Description = topicIn.Description
err = topic.Insert(&user)
if err != nil {
log.Errorf("Error while InsertTopic %s", err)
ctx.JSON(http.StatusInternalServerError, err)
return
}
ctx.JSON(http.StatusCreated, topic)
}