Merge pull request #5 from gwinn/master

improve ws url generation
This commit is contained in:
Alex Lushpai 2018-08-31 17:57:19 +03:00 committed by GitHub
commit 109ad20fc0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"net/http"
"strings"
"time"
"github.com/google/go-querystring/query"
@ -659,9 +660,9 @@ func (c *MgClient) CommandDelete(request string) (map[string]interface{}, int, e
return resp, status, err
}
// Ws let you receive url & headers to open web socket connection
func (c *MgClient) Ws() (string, http.Header, error) {
url := fmt.Sprintf("%s%s%s", c.URL, prefix, "/ws")
// WsMeta let you receive url & headers to open web socket connection
func (c *MgClient) WsMeta(events []string) (string, http.Header, error) {
url := fmt.Sprintf("%s%s%s%s", c.URL, prefix, "/ws?events=", strings.Join(events[:], ","))
headers := http.Header{}
headers.Add("x-bot-token", c.Token)
@ -670,6 +671,11 @@ func (c *MgClient) Ws() (string, http.Header, error) {
return url, headers, err
}
if len(events) < 1 {
err := errors.New("events list must not be empty")
return url, headers, err
}
return url, headers, nil
}