diff --git a/v1/client.go b/v1/client.go index efc9e65..fc66d00 100644 --- a/v1/client.go +++ b/v1/client.go @@ -912,20 +912,20 @@ func (c *MgClient) UploadFileByURL(request UploadFileByUrlRequest) (UploadFileRe return resp, status, err } -type wsOptions struct { - params []string +type wsParams struct { + options []string } -type WsOption interface { - apply(*wsOptions) +type WsParams interface { + apply(*wsParams) } -func (c WsOptionParam) apply(opts *wsOptions) { - opts.params = append(opts.params, string(c)) +func (c WsOption) apply(opts *wsParams) { + opts.options = append(opts.options, string(c)) } // WsMeta let you receive url & headers to open web socket connection -func (c *MgClient) WsMeta(events []string, opts ...WsOption) (string, http.Header, error) { +func (c *MgClient) WsMeta(events []string, opts ...WsParams) (string, http.Header, error) { var url string if len(events) < 1 { @@ -935,12 +935,12 @@ func (c *MgClient) WsMeta(events []string, opts ...WsOption) (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 wsOptions + var wsOpts wsParams for _, opt := range opts { opt.apply(&wsOpts) } - if len(wsOpts.params) > 0 { - url = fmt.Sprintf("%s&options=%s", url, strings.Join(wsOpts.params, ",")) + if len(wsOpts.options) > 0 { + url = fmt.Sprintf("%s&options=%s", url, strings.Join(wsOpts.options, ",")) } if url == "" { diff --git a/v1/client_test.go b/v1/client_test.go index 718b538..d3ba722 100644 --- a/v1/client_test.go +++ b/v1/client_test.go @@ -849,7 +849,7 @@ func TestMgClient_CommandEditDelete(t *testing.T) { func TestMgClient_WsMeta_With_Options(t *testing.T) { c := client() events := []string{"user_updated", "user_join_chat"} - options := []WsOption{WsOptionIncludeMassCommunication} + options := []WsParams{WsOptionIncludeMassCommunication} url, headers, err := c.WsMeta(events, options...) @@ -857,10 +857,10 @@ func TestMgClient_WsMeta_With_Options(t *testing.T) { t.Errorf("%v", err) } - resUrl := "wss://api.example.com/api/bot/v1/ws?events=user_updated,user_join_chat&options=include_mass_communication" + resURL := "wss://api.example.com/api/bot/v1/ws?events=user_updated,user_join_chat&options=include_mass_communication" resToken := c.Token - assert.Equal(t, resUrl, url) + assert.Equal(t, resURL, url) assert.Equal(t, resToken, headers["X-Bot-Token"][0]) } @@ -873,10 +873,10 @@ func TestMgClient_WsMeta(t *testing.T) { t.Errorf("%v", err) } - resUrl := fmt.Sprintf("%s%s%s%s", strings.Replace(c.URL, "https", "wss", 1), prefix, "/ws?events=", strings.Join(events[:], ",")) + resURL := fmt.Sprintf("%s%s%s%s", strings.Replace(c.URL, "https", "wss", 1), prefix, "/ws?events=", strings.Join(events[:], ",")) resToken := c.Token - assert.Equal(t, resUrl, url) + assert.Equal(t, resURL, url) assert.Equal(t, resToken, headers["X-Bot-Token"][0]) } diff --git a/v1/types.go b/v1/types.go index 4261892..cf1f146 100644 --- a/v1/types.go +++ b/v1/types.go @@ -43,7 +43,7 @@ const ( WsEventSettingsUpdated string = "settings_updated" WsEventChatsDeleted string = "chats_deleted" - WsOptionIncludeMassCommunication WsOptionParam = "include_mass_communication" + WsOptionIncludeMassCommunication WsOption = "include_mass_communication" ChannelFeatureNone string = "none" ChannelFeatureReceive string = "receive" @@ -438,7 +438,7 @@ type ( // WS options type ( - WsOptionParam string + WsOption string ) // Single entity types