本文整理汇总了Golang中github.com/mattermost/platform/model.NewClient函数的典型用法代码示例。如果您正苦于以下问题:Golang NewClient函数的具体用法?Golang NewClient怎么用?Golang NewClient使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewClient函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: loadTestUsersCommand
func loadTestUsersCommand(c *Context, command *model.Command) bool {
cmd1 := cmds["loadTestCommand"] + " users"
cmd2 := cmds["loadTestCommand"] + " users fuzz"
if strings.Index(command.Command, cmd1) == 0 && !command.Suggest {
cmd := cmd1
doFuzz := false
if strings.Index(command.Command, cmd2) == 0 {
doFuzz = true
cmd = cmd2
}
usersr, err := parseRange(command.Command, cmd)
if err == false {
usersr = utils.Range{10, 15}
}
client := model.NewClient(c.GetSiteURL())
userCreator := NewAutoUserCreator(client, c.Session.TeamId)
userCreator.Fuzzy = doFuzz
userCreator.CreateTestUsers(usersr)
return true
} else if strings.Index(cmd1, command.Command) == 0 {
command.AddSuggestion(&model.SuggestCommand{Suggestion: cmd1, Description: c.T("api.command.load_test_users_command.users.description")})
command.AddSuggestion(&model.SuggestCommand{Suggestion: cmd2, Description: c.T("api.command.load_test_users_command.fuzz.description")})
} else if strings.Index(cmd2, command.Command) == 0 {
command.AddSuggestion(&model.SuggestCommand{Suggestion: cmd2, Description: c.T("api.command.load_test_users_command.fuzz.description")})
}
return false
}
开发者ID:bitbackofen,项目名称:platform,代码行数:29,代码来源:command.go
示例2: ChannelsCommand
func (me *LoadTestProvider) ChannelsCommand(c *Context, channelId string, message string) *model.CommandResponse {
cmd := strings.TrimSpace(strings.TrimPrefix(message, "channels"))
doFuzz := false
if strings.Index(cmd, "fuzz") == 0 {
doFuzz = true
cmd = strings.TrimSpace(strings.TrimPrefix(cmd, "fuzz"))
}
channelsr, err := parseRange(cmd, "")
if err == false {
channelsr = utils.Range{2, 5}
}
var team *model.Team
if tr := <-Srv.Store.Team().Get(c.TeamId); tr.Err != nil {
return &model.CommandResponse{Text: "Failed to create testing environment", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
} else {
team = tr.Data.(*model.Team)
}
client := model.NewClient(c.GetSiteURL())
client.SetTeamId(team.Id)
client.MockSession(c.Session.Token)
channelCreator := NewAutoChannelCreator(client, team)
channelCreator.Fuzzy = doFuzz
channelCreator.CreateTestChannels(channelsr)
return &model.CommandResponse{Text: "Added channels", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
}
开发者ID:ChrisOHu,项目名称:platform,代码行数:30,代码来源:command_loadtest.go
示例3: loadTestChannelsCommand
func loadTestChannelsCommand(c *Context, command *model.Command) bool {
cmd1 := cmds["loadTestCommand"] + " channels"
cmd2 := cmds["loadTestCommand"] + " channels fuzz"
if strings.Index(command.Command, cmd1) == 0 && !command.Suggest {
cmd := cmd1
doFuzz := false
if strings.Index(command.Command, cmd2) == 0 {
doFuzz = true
cmd = cmd2
}
channelsr, err := parseRange(command.Command, cmd)
if err == false {
channelsr = utils.Range{20, 30}
}
client := model.NewClient(c.GetSiteURL())
client.MockSession(c.Session.Token)
channelCreator := NewAutoChannelCreator(client, c.Session.TeamId)
channelCreator.Fuzzy = doFuzz
channelCreator.CreateTestChannels(channelsr)
return true
} else if strings.Index(cmd1, command.Command) == 0 {
command.AddSuggestion(&model.SuggestCommand{Suggestion: cmd1, Description: c.T("api.command.load_test_channels_command.channel.description")})
command.AddSuggestion(&model.SuggestCommand{Suggestion: cmd2, Description: c.T("api.command.load_test_channels_command.fuzz.description")})
} else if strings.Index(cmd2, command.Command) == 0 {
command.AddSuggestion(&model.SuggestCommand{Suggestion: cmd2, Description: c.T("api.command.load_test_channels_command.fuzz.description")})
}
return false
}
开发者ID:bitbackofen,项目名称:platform,代码行数:30,代码来源:command.go
示例4: loadTestChannelsCommand
func loadTestChannelsCommand(c *Context, command *model.Command) bool {
cmd1 := "/loadtest channels"
cmd2 := "/loadtest channels fuzz"
if strings.Index(command.Command, cmd1) == 0 && !command.Suggest {
cmd := cmd1
doFuzz := false
if strings.Index(command.Command, cmd2) == 0 {
doFuzz = true
cmd = cmd2
}
channelsr, err := parseRange(command.Command, cmd)
if err == false {
channelsr = utils.Range{20, 30}
}
client := model.NewClient(c.GetSiteURL())
client.MockSession(c.Session.Token)
channelCreator := NewAutoChannelCreator(client, c.Session.TeamId)
channelCreator.Fuzzy = doFuzz
channelCreator.CreateTestChannels(channelsr)
return true
} else if strings.Index(cmd1, command.Command) == 0 {
command.AddSuggestion(&model.SuggestCommand{Suggestion: cmd1, Description: "Add a specified number of random channels to current team <MinChannels> <MaxChannels>"})
command.AddSuggestion(&model.SuggestCommand{Suggestion: cmd2, Description: "Add a specified number of random channels with fuzz text to current team <Min Channels> <Max Channels>"})
} else if strings.Index(cmd2, command.Command) == 0 {
command.AddSuggestion(&model.SuggestCommand{Suggestion: cmd2, Description: "Add a specified number of random channels with fuzz text to current team <Min Channels> <Max Channels>"})
}
return false
}
开发者ID:robertkraig,项目名称:platform,代码行数:30,代码来源:command.go
示例5: loadTestUsersCommand
func loadTestUsersCommand(c *Context, command *model.Command) bool {
cmd1 := "/loadtest users"
cmd2 := "/loadtest users fuzz"
if strings.Index(command.Command, cmd1) == 0 && !command.Suggest {
cmd := cmd1
doFuzz := false
if strings.Index(command.Command, cmd2) == 0 {
doFuzz = true
cmd = cmd2
}
usersr, err := parseRange(command.Command, cmd)
if err == false {
usersr = utils.Range{10, 15}
}
client := model.NewClient(c.GetSiteURL())
userCreator := NewAutoUserCreator(client, c.Session.TeamId)
userCreator.Fuzzy = doFuzz
userCreator.CreateTestUsers(usersr)
return true
} else if strings.Index(cmd1, command.Command) == 0 {
command.AddSuggestion(&model.SuggestCommand{Suggestion: cmd1, Description: "Add a specified number of random users to current team <Min Users> <Max Users>"})
command.AddSuggestion(&model.SuggestCommand{Suggestion: cmd2, Description: "Add a specified number of random users with fuzz text to current team <Min Users> <Max Users>"})
} else if strings.Index(cmd2, command.Command) == 0 {
command.AddSuggestion(&model.SuggestCommand{Suggestion: cmd2, Description: "Add a specified number of random users with fuzz text to current team <Min Users> <Max Users>"})
}
return false
}
开发者ID:robertkraig,项目名称:platform,代码行数:29,代码来源:command.go
示例6: 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
示例7: Setup
func Setup() {
if Srv == nil {
utils.LoadConfig("config.json")
NewServer()
StartServer()
InitApi()
Client = model.NewClient("http://localhost:" + utils.Cfg.ServiceSettings.Port + "/api/v1")
}
}
开发者ID:crspeller,项目名称:platform,代码行数:9,代码来源:api_test.go
示例8: Setup
func Setup() {
if Srv == nil {
utils.LoadConfig("config.json")
utils.Cfg.TeamSettings.MaxUsersPerTeam = 50
NewServer()
StartServer()
InitApi()
Client = model.NewClient("http://localhost" + utils.Cfg.ServiceSettings.ListenAddress)
}
}
开发者ID:no2key,项目名称:platform,代码行数:10,代码来源:api_test.go
示例9: Setup
func Setup() {
if api.Srv == nil {
utils.LoadConfig("config.json")
api.NewServer()
api.StartServer()
api.InitApi()
InitWeb()
URL = "http://localhost" + utils.Cfg.ServiceSettings.ListenAddress
ApiClient = model.NewClient(URL)
}
}
开发者ID:Nodeer,项目名称:platform,代码行数:11,代码来源:web_test.go
示例10: Setup
func Setup() {
if Srv == nil {
utils.LoadConfig("config.json")
utils.InitTranslations()
utils.Cfg.TeamSettings.MaxUsersPerTeam = 50
NewServer()
StartServer()
InitApi()
Client = model.NewClient("http://localhost" + utils.Cfg.ServiceSettings.ListenAddress)
Srv.Store.MarkSystemRanUnitTests()
}
}
开发者ID:bitbackofen,项目名称:platform,代码行数:13,代码来源:api_test.go
示例11: FindTeamByDomain
func FindTeamByDomain(c *Context, domain string, all string) bool {
if domain == "" || len(domain) > 64 {
c.SetInvalidParam("findTeamByDomain", "domain")
return false
}
if model.IsReservedDomain(domain) {
c.Err = model.NewAppError("findTeamByDomain", "This URL is unavailable. Please try another.", "d="+domain)
return false
}
if all == "false" {
if result := <-Srv.Store.Team().GetByDomain(domain); result.Err != nil {
return false
} else {
return true
}
} else {
if doesSubDomainExist(domain) {
return true
}
protocol := "http"
if utils.Cfg.ServiceSettings.UseSSL {
protocol = "https"
}
for key, _ := range utils.Cfg.ServiceSettings.Shards {
url := fmt.Sprintf("%v://%v.%v/api/v1", protocol, key, utils.Cfg.ServiceSettings.Domain)
if strings.Index(utils.Cfg.ServiceSettings.Domain, "localhost") == 0 {
url = fmt.Sprintf("%v://%v/api/v1", protocol, utils.Cfg.ServiceSettings.Domain)
}
client := model.NewClient(url)
if result, err := client.FindTeamByDomain(domain, false); err != nil {
c.Err = err
return false
} else {
if result.Data.(bool) {
return true
}
}
}
return false
}
}
开发者ID:rasheedamir,项目名称:platform,代码行数:51,代码来源:team.go
示例12: Setup
func Setup() {
if api.Srv == nil {
utils.LoadConfig("config.json")
utils.InitTranslations()
api.NewServer()
api.StartServer()
api.InitApi()
InitWeb()
URL = "http://localhost" + utils.Cfg.ServiceSettings.ListenAddress
ApiClient = model.NewClient(URL)
api.Srv.Store.MarkSystemRanUnitTests()
}
}
开发者ID:bitbackofen,项目名称:platform,代码行数:14,代码来源:web_test.go
示例13: 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
示例14: Setup
func Setup() {
if api.Srv == nil {
utils.TranslationsPreInit()
utils.LoadConfig("config.json")
utils.InitTranslations(utils.Cfg.LocalizationSettings)
api.NewServer(false)
api.StartServer()
api.InitApi()
InitWeb()
URL = "http://localhost" + utils.Cfg.ServiceSettings.ListenAddress
ApiClient = model.NewClient(URL)
api.Srv.Store.MarkSystemRanUnitTests()
*utils.Cfg.TeamSettings.EnableOpenServer = true
}
}
开发者ID:duzhanyuan,项目名称:platform,代码行数:17,代码来源:web_test.go
示例15: emailTeams
func emailTeams(c *Context, w http.ResponseWriter, r *http.Request) {
m := model.MapFromJson(r.Body)
email := strings.ToLower(strings.TrimSpace(m["email"]))
if email == "" {
c.SetInvalidParam("findTeam", "email")
return
}
protocol := "http"
if utils.Cfg.ServiceSettings.UseSSL {
protocol = "https"
}
subjectPage := NewServerTemplatePage("find_teams_subject", c.TeamUrl)
bodyPage := NewServerTemplatePage("find_teams_body", c.TeamUrl)
for key, _ := range utils.Cfg.ServiceSettings.Shards {
url := fmt.Sprintf("%v://%v.%v/api/v1", protocol, key, utils.Cfg.ServiceSettings.Domain)
if strings.Index(utils.Cfg.ServiceSettings.Domain, "localhost") == 0 {
url = fmt.Sprintf("%v://%v/api/v1", protocol, utils.Cfg.ServiceSettings.Domain)
}
client := model.NewClient(url)
if result, err := client.FindTeams(email); err != nil {
l4g.Error("An error occured while finding teams at %v err=%v", key, err)
} else {
data := result.Data.([]string)
for _, domain := range data {
bodyPage.Props[fmt.Sprintf("%v://%v.%v", protocol, domain, utils.Cfg.ServiceSettings.Domain)] = ""
}
}
}
if err := utils.SendMail(email, subjectPage.Render(), bodyPage.Render()); err != nil {
l4g.Error("An error occured while sending an email in emailTeams err=%v", err)
}
w.Write([]byte(model.MapToJson(m)))
}
开发者ID:rasheedamir,项目名称:platform,代码行数:45,代码来源:team.go
示例16: ChannelsCommand
func (me *LoadTestProvider) ChannelsCommand(c *Context, channelId string, message string) *model.CommandResponse {
cmd := strings.TrimSpace(strings.TrimPrefix(message, "channels"))
doFuzz := false
if strings.Index(cmd, "fuzz") == 0 {
doFuzz = true
cmd = strings.TrimSpace(strings.TrimPrefix(cmd, "fuzz"))
}
channelsr, err := parseRange(cmd, "")
if err == false {
channelsr = utils.Range{2, 5}
}
client := model.NewClient(c.GetSiteURL())
client.MockSession(c.Session.Token)
channelCreator := NewAutoChannelCreator(client, c.Session.TeamId)
channelCreator.Fuzzy = doFuzz
channelCreator.CreateTestChannels(channelsr)
return &model.CommandResponse{Text: "Adding channels...", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
}
开发者ID:ZBoxApp,项目名称:platform,代码行数:21,代码来源:command_loadtest.go
示例17: loginToMattermost
func (u *User) loginToMattermost() error {
b := &backoff.Backoff{
Min: time.Second,
Max: 5 * time.Minute,
Jitter: true,
}
// login to mattermost
//u.Credentials = &MmCredentials{Server: url, Team: team, Login: email, Pass: pass}
MmClient := model.NewClient("https://" + u.Credentials.Server)
var myinfo *model.Result
var appErr *model.AppError
for {
logger.Debug("retrying login", u.Credentials.Team, u.Credentials.Login, u.Credentials.Server)
myinfo, appErr = MmClient.LoginByEmail(u.Credentials.Team, u.Credentials.Login, u.Credentials.Pass)
if appErr != nil {
d := b.Duration()
if !strings.Contains(appErr.DetailedError, "connection refused") &&
!strings.Contains(appErr.DetailedError, "invalid character") {
return errors.New(appErr.Message)
}
logger.Infof("LOGIN: %s, reconnecting in %s", appErr, d)
time.Sleep(d)
continue
}
break
}
// reset timer
b.Reset()
u.MmUser = myinfo.Data.(*model.User)
myinfo, _ = MmClient.GetMyTeam("")
u.MmTeam = myinfo.Data.(*model.Team)
// setup websocket connection
wsurl := "wss://" + u.Credentials.Server + "/api/v1/websocket"
header := http.Header{}
header.Set(model.HEADER_AUTH, "BEARER "+MmClient.AuthToken)
var WsClient *websocket.Conn
var err error
for {
WsClient, _, err = websocket.DefaultDialer.Dial(wsurl, header)
if err != nil {
d := b.Duration()
logger.Infof("WSS: %s, reconnecting in %s", err, d)
time.Sleep(d)
continue
}
break
}
b.Reset()
u.MmClient = MmClient
u.MmWsClient = WsClient
// populating users
u.updateMMUsers()
// populating channels
u.updateMMChannels()
// fetch users and channels from mattermost
u.addUsersToChannels()
return nil
}
开发者ID:yuvipanda,项目名称:mm-go-irckit,代码行数:66,代码来源:mmuser.go
示例18: TestGetChannelExtraInfo
func TestGetChannelExtraInfo(t *testing.T) {
Setup()
team := &model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "[email protected]", Type: model.TEAM_OPEN}
team = Client.Must(Client.CreateTeam(team)).Data.(*model.Team)
user := &model.User{TeamId: team.Id, Email: model.NewId() + "[email protected]", Nickname: "Corey Hulen", Password: "pwd"}
user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User)
store.Must(Srv.Store.User().VerifyEmail(user.Id))
Client.LoginByEmail(team.Name, user.Email, "pwd")
channel1 := &model.Channel{DisplayName: "A Test API Name", Name: "a" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id}
channel1 = Client.Must(Client.CreateChannel(channel1)).Data.(*model.Channel)
rget := Client.Must(Client.GetChannelExtraInfo(channel1.Id, ""))
data := rget.Data.(*model.ChannelExtra)
if data.Id != channel1.Id {
t.Fatal("couldnt't get extra info")
}
//
// Testing etag caching
//
currentEtag := rget.Etag
if cache_result, err := Client.GetChannelExtraInfo(channel1.Id, currentEtag); err != nil {
t.Fatal(err)
} else if cache_result.Data.(*model.ChannelExtra) != nil {
t.Log(cache_result.Data)
t.Fatal("response should be empty")
} else {
currentEtag = cache_result.Etag
}
Client2 := model.NewClient("http://localhost" + utils.Cfg.ServiceSettings.ListenAddress)
user2 := &model.User{TeamId: team.Id, Email: model.NewId() + "[email protected]", Nickname: "Tester 2", Password: "pwd"}
user2 = Client2.Must(Client2.CreateUser(user2, "")).Data.(*model.User)
store.Must(Srv.Store.User().VerifyEmail(user2.Id))
Client2.LoginByEmail(team.Name, user2.Email, "pwd")
Client2.Must(Client2.JoinChannel(channel1.Id))
if cache_result, err := Client.GetChannelExtraInfo(channel1.Id, currentEtag); err != nil {
t.Fatal(err)
} else if cache_result.Data.(*model.ChannelExtra) == nil {
t.Log(cache_result.Data)
t.Fatal("response should not be empty")
} else {
currentEtag = cache_result.Etag
}
if cache_result, err := Client.GetChannelExtraInfo(channel1.Id, currentEtag); err != nil {
t.Fatal(err)
} else if cache_result.Data.(*model.ChannelExtra) != nil {
t.Log(cache_result.Data)
t.Fatal("response should be empty")
} else {
currentEtag = cache_result.Etag
}
Client2.Must(Client2.LeaveChannel(channel1.Id))
if cache_result, err := Client.GetChannelExtraInfo(channel1.Id, currentEtag); err != nil {
t.Fatal(err)
} else if cache_result.Data.(*model.ChannelExtra) == nil {
t.Log(cache_result.Data)
t.Fatal("response should not be empty")
} else {
currentEtag = cache_result.Etag
}
if cache_result, err := Client.GetChannelExtraInfo(channel1.Id, currentEtag); err != nil {
t.Fatal(err)
} else if cache_result.Data.(*model.ChannelExtra) != nil {
t.Log(cache_result.Data)
t.Fatal("response should be empty")
} else {
currentEtag = cache_result.Etag
}
}
开发者ID:nikwins,项目名称:platform,代码行数:83,代码来源:channel_test.go
示例19: Login
func (m *MMClient) Login() error {
if m.WsQuit {
return nil
}
b := &backoff.Backoff{
Min: time.Second,
Max: 5 * time.Minute,
Jitter: true,
}
uriScheme := "https://"
wsScheme := "wss://"
if m.NoTLS {
uriScheme = "http://"
wsScheme = "ws://"
}
// login to mattermost
m.Client = model.NewClient(uriScheme + m.Credentials.Server)
m.Client.HttpClient.Transport = &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: m.SkipTLSVerify}}
var myinfo *model.Result
var appErr *model.AppError
var logmsg = "trying login"
for {
m.log.Debugf("%s %s %s %s", logmsg, m.Credentials.Team, m.Credentials.Login, m.Credentials.Server)
if strings.Contains(m.Credentials.Pass, model.SESSION_COOKIE_TOKEN) {
m.log.Debugf(logmsg+" with ", model.SESSION_COOKIE_TOKEN)
token := strings.Split(m.Credentials.Pass, model.SESSION_COOKIE_TOKEN+"=")
m.Client.HttpClient.Jar = m.createCookieJar(token[1])
m.Client.MockSession(token[1])
myinfo, appErr = m.Client.GetMe("")
if myinfo.Data.(*model.User) == nil {
m.log.Errorf("LOGIN TOKEN: %s is invalid", m.Credentials.Pass)
return errors.New("invalid " + model.SESSION_COOKIE_TOKEN)
}
} else {
myinfo, appErr = m.Client.Login(m.Credentials.Login, m.Credentials.Pass)
}
if appErr != nil {
d := b.Duration()
m.log.Debug(appErr.DetailedError)
if !strings.Contains(appErr.DetailedError, "connection refused") &&
!strings.Contains(appErr.DetailedError, "invalid character") {
if appErr.Message == "" {
return errors.New(appErr.DetailedError)
}
return errors.New(appErr.Message)
}
m.log.Debugf("LOGIN: %s, reconnecting in %s", appErr, d)
time.Sleep(d)
logmsg = "retrying login"
continue
}
break
}
// reset timer
b.Reset()
initLoad, _ := m.Client.GetInitialLoad()
initData := initLoad.Data.(*model.InitialLoad)
m.User = initData.User
for _, v := range initData.Teams {
m.log.Debugf("trying %s (id: %s)", v.Name, v.Id)
if v.Name == m.Credentials.Team {
m.Client.SetTeamId(v.Id)
m.Team = v
m.log.Debugf("GetallTeamListings: found id %s for team %s", v.Id, v.Name)
break
}
}
if m.Team == nil {
return errors.New("team not found")
}
// setup websocket connection
wsurl := wsScheme + m.Credentials.Server + "/api/v3/users/websocket"
header := http.Header{}
header.Set(model.HEADER_AUTH, "BEARER "+m.Client.AuthToken)
m.log.Debug("WsClient: making connection")
var err error
for {
wsDialer := &websocket.Dialer{Proxy: http.ProxyFromEnvironment, TLSClientConfig: &tls.Config{InsecureSkipVerify: m.SkipTLSVerify}}
m.WsClient, _, err = wsDialer.Dial(wsurl, header)
if err != nil {
d := b.Duration()
m.log.Debugf("WSS: %s, reconnecting in %s", err, d)
time.Sleep(d)
continue
}
break
}
b.Reset()
// populating users
m.UpdateUsers()
// populating channels
m.UpdateChannels()
return nil
}
开发者ID:42wim,项目名称:matterbridge,代码行数:100,代码来源:matterclient.go
示例20: CreateClient
func (me *TestHelper) CreateClient() *model.Client {
return model.NewClient("http://localhost" + utils.Cfg.ServiceSettings.ListenAddress)
}
开发者ID:ReinhardHsu,项目名称:platform,代码行数:3,代码来源:apitestlib.go
注:本文中的github.com/mattermost/platform/model.NewClient函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论