From 60d8d3f95a57dd56a20d2ee265e356e48f2c3585 Mon Sep 17 00:00:00 2001 From: Sergey Parshukov Date: Thu, 25 Jul 2019 14:37:27 +0300 Subject: [PATCH] Fixed staticcheck warnings --- examples/linked-account/main.go | 1 - go.sum | 6 ++++++ messenger.go | 8 ++++---- messenger_test.go | 2 +- pass_thread_control.go | 12 ------------ response.go | 5 ++++- 6 files changed, 15 insertions(+), 19 deletions(-) create mode 100644 go.sum diff --git a/examples/linked-account/main.go b/examples/linked-account/main.go index 7bb9dc6..b70ac4f 100644 --- a/examples/linked-account/main.go +++ b/examples/linked-account/main.go @@ -17,7 +17,6 @@ import ( const ( webhooksPath = "/webhooks" loginPath = "/signin" - logoutPath = "/signout" validUsername = "john" validPassword = "secret" diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..e03ee77 --- /dev/null +++ b/go.sum @@ -0,0 +1,6 @@ +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= diff --git a/messenger.go b/messenger.go index 67f43c3..8629c01 100644 --- a/messenger.go +++ b/messenger.go @@ -19,7 +19,7 @@ const ( // SendSettingsURL is API endpoint for saving settings. SendSettingsURL = "https://graph.facebook.com/v2.6/me/thread_settings" - // MessengerProfileURL is the API endoint where yout bot set properties that define various aspects of the following Messenger Platform features. + // MessengerProfileURL is the API endpoint where you set properties that define various aspects of the following Messenger Platform features. // Used in the form https://graph.facebook.com/v2.6/me/messenger_profile?access_token= // https://developers.facebook.com/docs/messenger-platform/reference/messenger-profile-api/ MessengerProfileURL = "https://graph.facebook.com/v2.6/me/messenger_profile" @@ -192,7 +192,7 @@ func (m *Messenger) ProfileByID(id int64, profileFields []string) (Profile, erro qr := QueryResponse{} err = json.Unmarshal(content, &qr) if qr.Error != nil { - err = fmt.Errorf("Facebook error : %s", qr.Error.Message) + err = fmt.Errorf("facebook error: %s", qr.Error.Message) } } @@ -341,7 +341,7 @@ func (m *Messenger) checkIntegrity(r *http.Request) error { func (m *Messenger) dispatch(r Receive) { for _, entry := range r.Entry { for _, info := range entry.Messaging { - a := m.classify(info, entry) + a := m.classify(info) if a == UnknownAction { fmt.Println("Unknown action:", info) continue @@ -478,7 +478,7 @@ func (m *Messenger) EnableChatExtension(homeURL HomeURL) error { } // classify determines what type of message a webhook event is. -func (m *Messenger) classify(info MessageInfo, e Entry) Action { +func (m *Messenger) classify(info MessageInfo) Action { if info.Message != nil { return TextAction } else if info.Delivery != nil { diff --git a/messenger_test.go b/messenger_test.go index 6a1ba00..7633894 100644 --- a/messenger_test.go +++ b/messenger_test.go @@ -56,7 +56,7 @@ func TestMessenger_Classify(t *testing.T) { }, } { t.Run("action "+name, func(t *testing.T) { - action := m.classify(test.msgInfo, Entry{}) + action := m.classify(test.msgInfo) assert.Exactly(t, action, test.expected) }) } diff --git a/pass_thread_control.go b/pass_thread_control.go index ca072f4..2c28785 100644 --- a/pass_thread_control.go +++ b/pass_thread_control.go @@ -1,17 +1,5 @@ package messenger -import "encoding/json" - -func unmarshalPassThreadControl(data []byte) (passThreadControl, error) { - var r passThreadControl - err := json.Unmarshal(data, &r) - return r, err -} - -func (r *passThreadControl) marshal() ([]byte, error) { - return json.Marshal(r) -} - type passThreadControl struct { Recipient Recipient `json:"recipient"` TargetAppID int64 `json:"target_app_id"` diff --git a/response.go b/response.go index 0d024fe..aa39bd1 100644 --- a/response.go +++ b/response.go @@ -77,8 +77,11 @@ func checkFacebookError(r io.Reader) error { qr := QueryResponse{} err = json.NewDecoder(r).Decode(&qr) + if err != nil { + return fmt.Errorf("json unmarshal error: %s", err) + } if qr.Error != nil { - err = fmt.Errorf("Facebook error : %s", qr.Error.Message) + err = fmt.Errorf("facebook error: %s", qr.Error.Message) return err }