From edd49a3f167d6c86d0ad41d74b676083f8333630 Mon Sep 17 00:00:00 2001 From: kha7iq Date: Wed, 28 Apr 2021 22:12:47 +0800 Subject: [PATCH] style: resovle linting issues --- cmd/discord.go | 2 +- cmd/mattermost.go | 11 +++++------ cmd/msteams.go | 1 - cmd/pushbullet.go | 2 -- cmd/rocketchat.go | 6 +++--- cmd/telegram.go | 6 +++--- 6 files changed, 12 insertions(+), 16 deletions(-) diff --git a/cmd/discord.go b/cmd/discord.go index d83f11a..964fb31 100644 --- a/cmd/discord.go +++ b/cmd/discord.go @@ -66,7 +66,7 @@ All configuration options are also available via environment variables.`, discordSvc := discord.New() if err := discordSvc.AuthenticateWithBotToken(discordOpts.Token); err != nil { - return fmt.Errorf("unable to authenticate %v\n", err) + return fmt.Errorf("unable to authenticate %v", err) } chn := strings.Split(discordOpts.Channel, ",") diff --git a/cmd/mattermost.go b/cmd/mattermost.go index e858567..449775a 100644 --- a/cmd/mattermost.go +++ b/cmd/mattermost.go @@ -18,7 +18,7 @@ type matterMost struct { Token string ServerURL string Scheme string - ApiURL string + APIURL string Message string ChanIDs string } @@ -108,7 +108,7 @@ You can specify multiple channels by separating the value with ','.`, EnvVars: []string{"MATTERMOST_SCHEME"}, }, &cli.StringFlag{ - Destination: &mattermostOpts.ApiURL, + Destination: &mattermostOpts.APIURL, Name: "api", Value: "/api/v4/posts", Usage: "Unless using older version of api default is fine.", @@ -116,7 +116,7 @@ You can specify multiple channels by separating the value with ','.`, }, }, Action: func(ctx *cli.Context) error { - endPointURL := mattermostOpts.Scheme + "://" + mattermostOpts.ServerURL + mattermostOpts.ApiURL + endPointURL := mattermostOpts.Scheme + "://" + mattermostOpts.ServerURL + mattermostOpts.APIURL // Create a Bearer string by appending string access token bearer := "Bearer " + mattermostOpts.Token @@ -129,7 +129,7 @@ You can specify multiple channels by separating the value with ','.`, return fmt.Errorf(EmptyChannel) } - jsonData, err := toJson(v, fullMessage) + jsonData, err := toJSON(v, fullMessage) if err != nil { return fmt.Errorf("error parsing json\n[ERROR] - %v", err) } @@ -137,7 +137,6 @@ You can specify multiple channels by separating the value with ','.`, if err := sendMattermost(endPointURL, bearer, jsonData); err != nil { return fmt.Errorf("failed to send message\n[ERROR] - %v", err) } - } return nil }, @@ -145,7 +144,7 @@ You can specify multiple channels by separating the value with ','.`, } // toJson takes strings and convert them to json byte array -func toJson(channel string, msg string) ([]byte, error) { +func toJSON(channel string, msg string) ([]byte, error) { m := make(map[string]string, 2) m["channel_id"] = channel m["message"] = msg diff --git a/cmd/msteams.go b/cmd/msteams.go index 78cead2..d0fac89 100644 --- a/cmd/msteams.go +++ b/cmd/msteams.go @@ -63,7 +63,6 @@ you can add permissions for multiple channels to single webhook.`, return fmt.Errorf(EmptyChannel) } teamsSvc.AddReceivers(v) - } notifier.UseServices(teamsSvc) diff --git a/cmd/pushbullet.go b/cmd/pushbullet.go index c19b9ef..6477ee4 100644 --- a/cmd/pushbullet.go +++ b/cmd/pushbullet.go @@ -105,7 +105,6 @@ Multiple device nicknames or numbers can be used separated by comma.`, ); err != nil { return err } - } default: pushBulletSvc := pushbullet.New(pushBulletOpts.Token) @@ -127,7 +126,6 @@ Multiple device nicknames or numbers can be used separated by comma.`, ); err != nil { return err } - } log.Println("Successfully sent!") diff --git a/cmd/rocketchat.go b/cmd/rocketchat.go index e024208..5ed4318 100644 --- a/cmd/rocketchat.go +++ b/cmd/rocketchat.go @@ -13,7 +13,7 @@ import ( type rocketChat struct { Token string - UserId string + UserID string Message string Channel string Title string @@ -43,7 +43,7 @@ All configuration options are also available via environment variables.`, " --channel 'alert' --msg 'some message'", Flags: []cli.Flag{ &cli.StringFlag{ - Destination: &rocketChatOpts.UserId, + Destination: &rocketChatOpts.UserID, Name: "userid", Aliases: []string{"id"}, Required: true, @@ -99,7 +99,7 @@ All configuration options are also available via environment variables.`, notifier := notify.New() rocketChatSvc, err := rocketchat.New(rocketChatOpts.ServerURL, rocketChatOpts.Scheme, - rocketChatOpts.UserId, rocketChatOpts.Token) + rocketChatOpts.UserID, rocketChatOpts.Token) if err != nil { return err } diff --git a/cmd/telegram.go b/cmd/telegram.go index c843452..8e1475f 100644 --- a/cmd/telegram.go +++ b/cmd/telegram.go @@ -77,9 +77,9 @@ All configuration options are also available via environment variables.`, if len(v) <= 0 { return fmt.Errorf(EmptyChannel) } - k, err := strconv.Atoi(v) - if err != nil { - log.Println(err) + k, errStr := strconv.Atoi(v) + if errStr != nil { + return errStr } telegramSvc.AddReceivers(int64(k)) }