当前位置: 首页>>代码示例>>Golang>>正文


Golang model.Client类代码示例

本文整理汇总了Golang中github.com/mattermost/platform/model.Client的典型用法代码示例。如果您正苦于以下问题:Golang Client类的具体用法?Golang Client怎么用?Golang Client使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Client类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: CreateTestEnviromentWithTeams

func CreateTestEnviromentWithTeams(client *model.Client, rangeTeams utils.Range, rangeChannels utils.Range, rangeUsers utils.Range, rangePosts utils.Range, fuzzy bool) (TestEnviroment, bool) {
	rand.Seed(time.Now().UTC().UnixNano())

	teamCreator := NewAutoTeamCreator(client)
	teamCreator.Fuzzy = fuzzy
	teams, err := teamCreator.CreateTestTeams(rangeTeams)
	if err != true {
		return TestEnviroment{}, false
	}

	enviroment := TestEnviroment{teams, make([]TeamEnviroment, len(teams))}

	for i, team := range teams {
		userCreator := NewAutoUserCreator(client, team.Id)
		userCreator.Fuzzy = fuzzy
		randomUser, err := userCreator.createRandomUser()
		if err != true {
			return TestEnviroment{}, false
		}
		client.LoginById(randomUser.Id, USER_PASSWORD)
		teamEnviroment, err := CreateTestEnviromentInTeam(client, team.Id, rangeChannels, rangeUsers, rangePosts, fuzzy)
		if err != true {
			return TestEnviroment{}, false
		}
		enviroment.Enviroments[i] = teamEnviroment
	}

	return enviroment, true
}
开发者ID:Dahlgren,项目名称:platform,代码行数:29,代码来源:auto_enviroment.go

示例2: uploadTestFile

func uploadTestFile(Client *model.Client, channelId string) ([]string, error) {
	body := &bytes.Buffer{}
	writer := multipart.NewWriter(body)
	part, err := writer.CreateFormFile("files", "test.png")
	if err != nil {
		return nil, err
	}

	// base 64 encoded version of handtinywhite.gif from http://probablyprogramming.com/2009/03/15/the-tiniest-gif-ever
	file, _ := base64.StdEncoding.DecodeString("R0lGODlhAQABAIABAP///wAAACwAAAAAAQABAAACAkQBADs=")

	if _, err := io.Copy(part, bytes.NewReader(file)); err != nil {
		return nil, err
	}

	field, err := writer.CreateFormField("channel_id")
	if err != nil {
		return nil, err
	}

	if _, err := field.Write([]byte(channelId)); err != nil {
		return nil, err
	}

	if err := writer.Close(); err != nil {
		return nil, err
	}

	if resp, err := Client.UploadPostAttachment(body.Bytes(), writer.FormDataContentType()); err != nil {
		return nil, err
	} else {
		return resp.Data.(*model.FileUploadResponse).Filenames, nil
	}
}
开发者ID:ChrisOHu,项目名称:platform,代码行数:34,代码来源:file_test.go

示例3: CreatePost

func (me *TestHelper) CreatePost(client *model.Client, channel *model.Channel) *model.Post {
	id := model.NewId()

	post := &model.Post{
		ChannelId: channel.Id,
		Message:   "message_" + id,
	}

	utils.DisableDebugLogForTest()
	r := client.Must(client.CreatePost(post)).Data.(*model.Post)
	utils.EnableDebugLogForTest()
	return r
}
开发者ID:ReinhardHsu,项目名称:platform,代码行数:13,代码来源:apitestlib.go

示例4: postMessage

// postMessage Create a post in Mattermost
func (m *MatterMail) postMessage(client *model.Client, channelID string, message string, fileIds []string) error {
	post := &model.Post{ChannelId: channelID, Message: message}

	if len(fileIds) > 0 {
		post.FileIds = fileIds
	}

	res, err := client.CreatePost(post)
	if res == nil {
		return err
	}

	return nil
}
开发者ID:rodrigocorsi2,项目名称:mattermail,代码行数:15,代码来源:mattermail.go

示例5: CreateTeam

func (me *TestHelper) CreateTeam(client *model.Client) *model.Team {
	id := model.NewId()
	team := &model.Team{
		DisplayName: "dn_" + id,
		Name:        "name" + id,
		Email:       "success+" + id + "@simulator.amazonses.com",
		Type:        model.TEAM_OPEN,
	}

	utils.DisableDebugLogForTest()
	r := client.Must(client.CreateTeam(team)).Data.(*model.Team)
	utils.EnableDebugLogForTest()
	return r
}
开发者ID:ReinhardHsu,项目名称:platform,代码行数:14,代码来源:apitestlib.go

示例6: createChannel

func (me *TestHelper) createChannel(client *model.Client, team *model.Team, channelType string) *model.Channel {
	id := model.NewId()

	channel := &model.Channel{
		DisplayName: "dn_" + id,
		Name:        "name_" + id,
		Type:        channelType,
		TeamId:      team.Id,
	}

	utils.DisableDebugLogForTest()
	r := client.Must(client.CreateChannel(channel)).Data.(*model.Channel)
	utils.EnableDebugLogForTest()
	return r
}
开发者ID:ReinhardHsu,项目名称:platform,代码行数:15,代码来源:apitestlib.go

示例7: CreateUser

func (me *TestHelper) CreateUser(client *model.Client) *model.User {
	id := model.NewId()

	user := &model.User{
		Email:    "success+" + id + "@simulator.amazonses.com",
		Username: "un_" + id,
		Nickname: "nn_" + id,
		Password: "Password1",
	}

	utils.DisableDebugLogForTest()
	ruser := client.Must(client.CreateUser(user, "")).Data.(*model.User)
	ruser.Password = "Password1"
	store.Must(Srv.Store.User().VerifyEmail(ruser.Id))
	utils.EnableDebugLogForTest()
	return ruser
}
开发者ID:ReinhardHsu,项目名称:platform,代码行数:17,代码来源:apitestlib.go

示例8: getDirectChannelIDByName

func (m *MatterMail) getDirectChannelIDByName(client *model.Client, channelList *model.ChannelList, userName string) string {

	if m.user.Username == userName {
		m.eror.Printf("Impossible create a Direct channel, Mattermail user (%v) equals destination user (%v)\n", m.user.Username, userName)
		return ""
	}

	//result, err := client.GetProfilesForDirectMessageList(client.GetTeamId())
	result, err := client.SearchUsers(model.UserSearch{
		AllowInactive: false,
		TeamId:        client.GetTeamId(),
		Term:          userName,
	})

	if err != nil {
		m.eror.Println("Error on SearchUsers: ", err.Error())
		return ""
	}

	profiles := result.Data.([]*model.User)
	var userID string

	for _, p := range profiles {
		if p.Username == userName {
			userID = p.Id
			break
		}
	}

	if userID == "" {
		m.debg.Println("Did not find the username:", userName)
		return ""
	}

	dmName := model.GetDMNameFromIds(m.user.Id, userID)
	dmID := getChannelIDByName(channelList, dmName)

	if dmID != "" {
		return dmID
	}

	m.debg.Println("Create direct channel to user:", userName)

	result, err = client.CreateDirectChannel(userID)
	if err != nil {
		m.eror.Println("Error on CreateDirectChannel: ", err.Error())
		return ""
	}

	directChannel := result.Data.(*model.Channel)
	return directChannel.Id
}
开发者ID:rodrigocorsi2,项目名称:mattermail,代码行数:52,代码来源:mattermail.go

示例9: 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

示例10: CreateBasicUser

// Basic test team and user so you always know one
func CreateBasicUser(client *model.Client) *model.AppError {
	result, _ := client.FindTeamByName(BTEST_TEAM_NAME, true)
	if result.Data.(bool) == false {
		newteam := &model.Team{DisplayName: BTEST_TEAM_DISPLAY_NAME, Name: BTEST_TEAM_NAME, Email: BTEST_TEAM_EMAIL, Type: BTEST_TEAM_TYPE}
		result, err := client.CreateTeam(newteam)
		if err != nil {
			return err
		}
		basicteam := result.Data.(*model.Team)
		newuser := &model.User{TeamId: basicteam.Id, Email: BTEST_USER_EMAIL, Nickname: BTEST_USER_NAME, Password: BTEST_USER_PASSWORD}
		result, err = client.CreateUser(newuser, "")
		if err != nil {
			return err
		}
		store.Must(Srv.Store.User().VerifyEmail(result.Data.(*model.User).Id))
	}
	return nil
}
开发者ID:mf1389004071,项目名称:platform,代码行数:19,代码来源:auto_users.go


注:本文中的github.com/mattermost/platform/model.Client类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。