This commit is contained in:
Alexey Chelnakov 2024-07-11 14:02:42 +03:00
parent de3eca3a55
commit 3e9078ee86
2 changed files with 8 additions and 8 deletions

View File

@ -925,7 +925,7 @@ func (c WsOption) apply(opts *wsParams) {
}
// WsMeta let you receive url & headers to open web socket connection
func (c *MgClient) WsMeta(events []string, opts ...WsParams) (string, http.Header, error) {
func (c *MgClient) WsMeta(events []string, urlParams ...WsParams) (string, http.Header, error) {
var url string
if len(events) < 1 {
@ -935,12 +935,12 @@ func (c *MgClient) WsMeta(events []string, opts ...WsParams) (string, http.Heade
url = fmt.Sprintf("%s%s%s%s", strings.Replace(c.URL, "https", "wss", 1), prefix, "/ws?events=", strings.Join(events[:], ","))
var wsOpts wsParams
for _, opt := range opts {
opt.apply(&wsOpts)
var params wsParams
for _, opt := range urlParams {
opt.apply(&params)
}
if len(wsOpts.options) > 0 {
url = fmt.Sprintf("%s&options=%s", url, strings.Join(wsOpts.options, ","))
if len(params.options) > 0 {
url = fmt.Sprintf("%s&options=%s", url, strings.Join(params.options, ","))
}
if url == "" {

View File

@ -849,9 +849,9 @@ func TestMgClient_CommandEditDelete(t *testing.T) {
func TestMgClient_WsMeta_With_Options(t *testing.T) {
c := client()
events := []string{"user_updated", "user_join_chat"}
options := []WsParams{WsOptionIncludeMassCommunication}
params := []WsParams{WsOptionIncludeMassCommunication}
url, headers, err := c.WsMeta(events, options...)
url, headers, err := c.WsMeta(events, params...)
if err != nil {
t.Errorf("%v", err)