本文整理汇总了Golang中socialapi/request.Query.Name方法的典型用法代码示例。如果您正苦于以下问题:Golang Query.Name方法的具体用法?Golang Query.Name怎么用?Golang Query.Name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类socialapi/request.Query
的用法示例。
在下文中一共展示了Query.Name方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: isInChannel
func (c *ChannelMessage) isInChannel(query *request.Query, channelName string) (bool, error) {
if c.Id == 0 {
return false, ErrChannelMessageIdIsNotSet
}
// fetch channel by group name
query.Name = query.GroupName
if query.GroupName == "koding" {
query.Name = channelName
}
ch := NewChannel()
channel, err := ch.ByName(query)
if err != nil {
return false, err
}
if channel.Id == 0 {
return false, ErrChannelIsNotSet
}
// check if message is in the channel
cml := NewChannelMessageList()
return cml.IsInChannel(c.Id, channel.Id)
}
示例2: TestPrivateMesssages
func TestPrivateMesssages(t *testing.T) {
tests.WithRunner(t, func(r *runner.Runner) {
Convey("while testing private channels", t, func() {
devrim, err := models.CreateAccountInBothDbsWithNick("devrim")
So(err, ShouldBeNil)
So(devrim, ShouldNotBeNil)
sinan, err := models.CreateAccountInBothDbsWithNick("sinan")
So(err, ShouldBeNil)
So(sinan, ShouldNotBeNil)
groupName := models.RandomGroupName()
// cretae admin user
account, err := models.CreateAccountInBothDbs()
tests.ResultedWithNoErrorCheck(account, err)
models.CreateTypedGroupedChannelWithTest(
account.Id,
models.Channel_TYPE_GROUP,
groupName,
)
// fetch admin's session
ses, err := modelhelper.FetchOrCreateSession(account.Nick, groupName)
So(err, ShouldBeNil)
So(ses, ShouldNotBeNil)
groupChannel, err := rest.CreateChannelByGroupNameAndType(
account.Id,
groupName,
models.Channel_TYPE_GROUP,
ses.ClientId,
)
tests.ResultedWithNoErrorCheck(groupChannel, err)
recipient := models.NewAccount()
recipient.OldId = AccountOldId2.Hex()
recipient, err = rest.CreateAccount(recipient)
So(err, ShouldBeNil)
So(recipient, ShouldNotBeNil)
recipient2 := models.NewAccount()
recipient2.OldId = AccountOldId3.Hex()
recipient2, err = rest.CreateAccount(recipient2)
So(err, ShouldBeNil)
So(recipient2, ShouldNotBeNil)
Convey("participants should be a member of parent group", func() {
pmr := models.ChannelRequest{}
pmr.AccountId = account.Id
pmr.Body = "this is a body message for private message @devrim @sinan"
pmr.GroupName = groupName
pmr.Recipients = []string{"devrim", "sinan"}
_, err := rest.SendPrivateChannelRequest(pmr, ses.ClientId)
So(err, ShouldNotBeNil)
})
_, err = groupChannel.AddParticipant(sinan.Id)
So(err, ShouldBeNil)
_, err = groupChannel.AddParticipant(devrim.Id)
So(err, ShouldBeNil)
Convey("one can send private message to one person", func() {
pmr := models.ChannelRequest{}
pmr.AccountId = account.Id
pmr.Body = "this is a body message for private message @devrim @sinan"
pmr.GroupName = groupName
pmr.Recipients = []string{"devrim", "sinan"}
cmc, err := rest.SendPrivateChannelRequest(pmr, ses.ClientId)
So(err, ShouldBeNil)
So(cmc, ShouldNotBeNil)
})
Convey("0 recipient should not fail", func() {
pmr := models.ChannelRequest{}
pmr.AccountId = account.Id
pmr.Body = "this is a body for private message"
pmr.GroupName = groupName
pmr.Recipients = []string{}
cmc, err := rest.SendPrivateChannelRequest(pmr, ses.ClientId)
So(err, ShouldBeNil)
So(cmc, ShouldNotBeNil)
})
Convey("if sender is not defined but token is added, then shouldn't fail to create PM", func() {
pmr := models.ChannelRequest{}
pmr.AccountId = 0
pmr.Body = "this is a body for private message"
pmr.GroupName = ""
pmr.Recipients = []string{}
cmc, err := rest.SendPrivateChannelRequest(pmr, ses.ClientId)
So(err, ShouldBeNil)
So(cmc, ShouldNotBeNil)
})
//.........这里部分代码省略.........
示例3: TestCollaborationChannels
func TestCollaborationChannels(t *testing.T) {
tests.WithRunner(t, func(r *runner.Runner) {
Convey("while testing collaboration channel", t, func() {
devrim, err := models.CreateAccountInBothDbsWithNick("devrim")
So(err, ShouldBeNil)
So(devrim, ShouldNotBeNil)
sinan, err := models.CreateAccountInBothDbsWithNick("sinan")
So(err, ShouldBeNil)
So(sinan, ShouldNotBeNil)
groupName := models.RandomGroupName()
// cretae admin user
account, err := models.CreateAccountInBothDbs()
tests.ResultedWithNoErrorCheck(account, err)
// fetch admin's session
ses, err := modelhelper.FetchOrCreateSession(account.Nick, groupName)
So(err, ShouldBeNil)
So(ses, ShouldNotBeNil)
groupChannel := models.CreateTypedGroupedChannelWithTest(
account.Id,
models.Channel_TYPE_GROUP,
groupName,
)
groupChannel.AddParticipant(account.Id)
_, err = groupChannel.AddParticipant(devrim.Id)
So(err, ShouldBeNil)
_, err = groupChannel.AddParticipant(sinan.Id)
So(err, ShouldBeNil)
recipient, err := models.CreateAccountInBothDbs()
tests.ResultedWithNoErrorCheck(recipient, err)
recipient2, err := models.CreateAccountInBothDbs()
tests.ResultedWithNoErrorCheck(recipient2, err)
Convey("one can send initiate the collaboration channel with only him", func() {
pmr := models.ChannelRequest{}
pmr.AccountId = account.Id
pmr.Body = "this is a body for private message"
pmr.GroupName = groupName
pmr.Recipients = []string{}
pmr.TypeConstant = models.Channel_TYPE_COLLABORATION
cmc, err := rest.SendPrivateChannelRequest(pmr, ses.ClientId)
So(err, ShouldBeNil)
So(cmc, ShouldNotBeNil)
})
Convey("one can send initiate the collaboration channel with 2 participants", func() {
pmr := models.ChannelRequest{}
pmr.AccountId = account.Id
pmr.Body = "this is a body message for private message @devrim @sinan"
pmr.GroupName = groupName
pmr.Recipients = []string{"devrim", "sinan"}
pmr.TypeConstant = models.Channel_TYPE_COLLABORATION
cmc, err := rest.SendPrivateChannelRequest(pmr, ses.ClientId)
So(err, ShouldBeNil)
So(cmc, ShouldNotBeNil)
})
Convey("if group name is nil, should not fail to create collaboration channel", func() {
ses, err := modelhelper.FetchOrCreateSession(sinan.Nick, "koding")
So(err, ShouldBeNil)
So(ses, ShouldNotBeNil)
groupChannel, err := rest.CreateChannelByGroupNameAndType(
sinan.Id,
"koding",
models.Channel_TYPE_GROUP,
ses.ClientId,
)
tests.ResultedWithNoErrorCheck(groupChannel, err)
groupChannel.AddParticipant(devrim.Id) // ignore error
groupChannel.AddParticipant(account.Id) // ignore error
groupChannel.AddParticipant(sinan.Id) // ignore error
pmr := models.ChannelRequest{}
pmr.AccountId = account.Id
pmr.Body = "this is a body for private message @devrim @sinan"
pmr.GroupName = ""
pmr.Recipients = []string{"devrim", "sinan"}
pmr.TypeConstant = models.Channel_TYPE_COLLABORATION
cmc, err := rest.SendPrivateChannelRequest(pmr, ses.ClientId)
So(err, ShouldBeNil)
So(cmc, ShouldNotBeNil)
})
// we give token as parameter to SendPrivateChannelRequest
// handler sets the accountId and groupname if not defined in handler's function
// So it should not return any error unless account is defined
Convey("if sender is not defined should not fail to create collaboration channel", func() {
pmr := models.ChannelRequest{}
//.........这里部分代码省略.........