本文整理汇总了Golang中github.com/mattermost/platform/utils.RandIntFromRange函数的典型用法代码示例。如果您正苦于以下问题:Golang RandIntFromRange函数的具体用法?Golang RandIntFromRange怎么用?Golang RandIntFromRange使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RandIntFromRange函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: loadTestPostsCommand
func loadTestPostsCommand(c *Context, command *model.Command) bool {
cmd1 := "/loadtest posts"
cmd2 := "/loadtest posts fuzz"
if strings.Index(command.Command, cmd1) == 0 && !command.Suggest {
cmd := cmd1
doFuzz := false
if strings.Index(command.Command, cmd2) == 0 {
cmd = cmd2
doFuzz = true
}
postsr, err := parseRange(command.Command, cmd)
if err == false {
postsr = utils.Range{20, 30}
}
tokens := strings.Fields(strings.TrimPrefix(command.Command, cmd))
rimages := utils.Range{0, 0}
if len(tokens) >= 3 {
if numImages, err := strconv.Atoi(tokens[2]); err == nil {
rimages = utils.Range{numImages, numImages}
}
}
var usernames []string
if result := <-Srv.Store.User().GetProfiles(c.Session.TeamId); result.Err == nil {
profileUsers := result.Data.(map[string]*model.User)
usernames = make([]string, len(profileUsers))
i := 0
for _, userprof := range profileUsers {
usernames[i] = userprof.Username
i++
}
}
client := model.NewClient(c.GetSiteURL())
client.MockSession(c.Session.Token)
testPoster := NewAutoPostCreator(client, command.ChannelId)
testPoster.Fuzzy = doFuzz
testPoster.Users = usernames
numImages := utils.RandIntFromRange(rimages)
numPosts := utils.RandIntFromRange(postsr)
for i := 0; i < numPosts; i++ {
testPoster.HasImage = (i < numImages)
testPoster.CreateRandomPost()
}
return true
} else if strings.Index(cmd1, command.Command) == 0 {
command.AddSuggestion(&model.SuggestCommand{Suggestion: cmd1, Description: "Add some random posts to current channel <Min Posts> <Max Posts> <Min Images> <Max Images>"})
command.AddSuggestion(&model.SuggestCommand{Suggestion: cmd2, Description: "Add some random posts with fuzz text to current channel <Min Posts> <Max Posts> <Min Images> <Max Images>"})
} else if strings.Index(cmd2, command.Command) == 0 {
command.AddSuggestion(&model.SuggestCommand{Suggestion: cmd2, Description: "Add some random posts with fuzz text to current channel <Min Posts> <Max Posts> <Min Images> <Max Images>"})
}
return false
}
开发者ID:robertkraig,项目名称:platform,代码行数:58,代码来源:command.go
示例2: CreateTestEnvironmentInTeam
func CreateTestEnvironmentInTeam(client *model.Client, team *model.Team, rangeChannels utils.Range, rangeUsers utils.Range, rangePosts utils.Range, fuzzy bool) (TeamEnvironment, bool) {
rand.Seed(time.Now().UTC().UnixNano())
// We need to create at least one user
if rangeUsers.Begin <= 0 {
rangeUsers.Begin = 1
}
userCreator := NewAutoUserCreator(client, team)
userCreator.Fuzzy = fuzzy
users, err := userCreator.CreateTestUsers(rangeUsers)
if err != true {
return TeamEnvironment{}, false
}
usernames := make([]string, len(users))
for i, user := range users {
usernames[i] = user.Username
}
channelCreator := NewAutoChannelCreator(client, team)
channelCreator.Fuzzy = fuzzy
channels, err := channelCreator.CreateTestChannels(rangeChannels)
// Have every user join every channel
for _, user := range users {
for _, channel := range channels {
client.LoginById(user.Id, USER_PASSWORD)
client.JoinChannel(channel.Id)
}
}
if err != true {
return TeamEnvironment{}, false
}
numPosts := utils.RandIntFromRange(rangePosts)
numImages := utils.RandIntFromRange(rangePosts) / 4
for j := 0; j < numPosts; j++ {
user := users[utils.RandIntFromRange(utils.Range{0, len(users) - 1})]
client.LoginById(user.Id, USER_PASSWORD)
for i, channel := range channels {
postCreator := NewAutoPostCreator(client, channel.Id)
postCreator.HasImage = i < numImages
postCreator.Users = usernames
postCreator.Fuzzy = fuzzy
postCreator.CreateRandomPost()
}
}
return TeamEnvironment{users, channels}, true
}
开发者ID:ChrisOHu,项目名称:platform,代码行数:51,代码来源:auto_environment.go
示例3: PostsCommand
func (me *LoadTestProvider) PostsCommand(c *Context, channelId string, message string) *model.CommandResponse {
cmd := strings.TrimSpace(strings.TrimPrefix(message, "posts"))
doFuzz := false
if strings.Index(cmd, "fuzz") == 0 {
doFuzz = true
cmd = strings.TrimSpace(strings.TrimPrefix(cmd, "fuzz"))
}
postsr, err := parseRange(cmd, "")
if err == false {
postsr = utils.Range{20, 30}
}
tokens := strings.Fields(cmd)
rimages := utils.Range{0, 0}
if len(tokens) >= 3 {
if numImages, err := strconv.Atoi(tokens[2]); err == nil {
rimages = utils.Range{numImages, numImages}
}
}
var usernames []string
if result := <-Srv.Store.User().GetProfiles(c.TeamId); result.Err == nil {
profileUsers := result.Data.(map[string]*model.User)
usernames = make([]string, len(profileUsers))
i := 0
for _, userprof := range profileUsers {
usernames[i] = userprof.Username
i++
}
}
client := model.NewClient(c.GetSiteURL())
client.SetTeamId(c.TeamId)
client.MockSession(c.Session.Token)
testPoster := NewAutoPostCreator(client, channelId)
testPoster.Fuzzy = doFuzz
testPoster.Users = usernames
numImages := utils.RandIntFromRange(rimages)
numPosts := utils.RandIntFromRange(postsr)
for i := 0; i < numPosts; i++ {
testPoster.HasImage = (i < numImages)
testPoster.CreateRandomPost()
}
return &model.CommandResponse{Text: "Added posts", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
}
开发者ID:ChrisOHu,项目名称:platform,代码行数:49,代码来源:command_loadtest.go
示例4: CreateTestPosts
func (cfg *AutoPostCreator) CreateTestPosts(rangePosts utils.Range) ([]*model.Post, bool) {
numPosts := utils.RandIntFromRange(rangePosts)
posts := make([]*model.Post, numPosts)
for i := 0; i < numPosts; i++ {
var err bool
posts[i], err = cfg.CreateRandomPost()
if err != true {
return posts, false
}
}
return posts, true
}
开发者ID:Rudloff,项目名称:platform,代码行数:14,代码来源:auto_posts.go
示例5: CreateTestTeams
func (cfg *AutoTeamCreator) CreateTestTeams(num utils.Range) ([]*model.Team, bool) {
numTeams := utils.RandIntFromRange(num)
teams := make([]*model.Team, numTeams)
for i := 0; i < numTeams; i++ {
var err bool
teams[i], err = cfg.createRandomTeam()
if err != true {
return teams, false
}
}
return teams, true
}
开发者ID:ChrisOHu,项目名称:platform,代码行数:14,代码来源:auto_teams.go
示例6: CreateTestUsers
func (cfg *AutoUserCreator) CreateTestUsers(num utils.Range) ([]*model.User, bool) {
numUsers := utils.RandIntFromRange(num)
users := make([]*model.User, numUsers)
for i := 0; i < numUsers; i++ {
var err bool
users[i], err = cfg.createRandomUser()
if err != true {
return users, false
}
}
return users, true
}
开发者ID:mf1389004071,项目名称:platform,代码行数:14,代码来源:auto_users.go
示例7: CreateTestChannels
func (cfg *AutoChannelCreator) CreateTestChannels(num utils.Range) ([]*model.Channel, bool) {
numChannels := utils.RandIntFromRange(num)
channels := make([]*model.Channel, numChannels)
for i := 0; i < numChannels; i++ {
var err bool
channels[i], err = cfg.createRandomChannel()
if err != true {
return channels, false
}
}
return channels, true
}
开发者ID:ChrisOHu,项目名称:platform,代码行数:14,代码来源:auto_channels.go
示例8: UploadTestFile
func (cfg *AutoPostCreator) UploadTestFile() ([]string, bool) {
body := &bytes.Buffer{}
writer := multipart.NewWriter(body)
filename := cfg.ImageFilenames[utils.RandIntFromRange(utils.Range{0, len(cfg.ImageFilenames) - 1})]
part, err := writer.CreateFormFile("files", filename)
if err != nil {
return nil, false
}
path := utils.FindDir("web/static/images")
file, err := os.Open(path + "/" + filename)
defer file.Close()
_, err = io.Copy(part, file)
if err != nil {
return nil, false
}
field, err := writer.CreateFormField("channel_id")
if err != nil {
return nil, false
}
_, err = field.Write([]byte(cfg.channelid))
if err != nil {
return nil, false
}
err = writer.Close()
if err != nil {
return nil, false
}
resp, appErr := cfg.client.UploadPostAttachment(body.Bytes(), writer.FormDataContentType())
if appErr != nil {
return nil, false
}
return resp.Data.(*model.FileUploadResponse).Filenames, true
}
开发者ID:ChrisOHu,项目名称:platform,代码行数:42,代码来源:auto_posts.go
示例9: UploadTestFile
func (cfg *AutoPostCreator) UploadTestFile() ([]string, bool) {
filename := cfg.ImageFilenames[utils.RandIntFromRange(utils.Range{0, len(cfg.ImageFilenames) - 1})]
path := utils.FindDir("web/static/images")
file, err := os.Open(path + "/" + filename)
defer file.Close()
data := &bytes.Buffer{}
_, err = io.Copy(data, file)
if err != nil {
return nil, false
}
resp, appErr := cfg.client.UploadPostAttachment(data.Bytes(), cfg.channelid, filename)
if appErr != nil {
return nil, false
}
return []string{resp.FileInfos[0].Id}, true
}
开发者ID:Rudloff,项目名称:platform,代码行数:20,代码来源:auto_posts.go
注:本文中的github.com/mattermost/platform/utils.RandIntFromRange函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论