diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c8b2dae..51ab474 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,16 +1,16 @@ stages: - - lint - build lint: - image: golang:latest - stage: lint + image: nixery.dev/shell/go/golangci-lint + stage: build before_script: + - cp /share/go/bin/go /bin && mkdir /tmp # fix weirdness from nixery image - mkdir -p /go/src/git.callpipe.com/finn/signald-go - cp -r * /go/src/git.callpipe.com/finn/signald-go - cd /go/src/git.callpipe.com/finn/signald-go script: - - gofmt -d . + - golangci-lint run build: stage: build diff --git a/cmd/signald-cli/cmd/link.go b/cmd/signald-cli/cmd/link.go index 81544a3..1bc2ee3 100644 --- a/cmd/signald-cli/cmd/link.go +++ b/cmd/signald-cli/cmd/link.go @@ -36,10 +36,13 @@ var linkCmd = &cobra.Command{ Long: `Get a URI or QR code to link to an existing Signal account`, Run: func(cmd *cobra.Command, args []string) { requestID := fmt.Sprint("signald-cli-", rand.Intn(1000)) - s.SendRequest(signald.Request{ + err := s.SendRequest(signald.Request{ Type: "link", ID: requestID, }) + if err != nil { + log.Fatal("error sending request: ", err) + } c := make(chan signald.Response) go s.Listen(c) @@ -50,7 +53,6 @@ var linkCmd = &cobra.Command{ case "linking_error": log.Fatal(message.Data.Message) os.Exit(1) - break case "linking_uri": if uriOrQR { @@ -58,14 +60,12 @@ var linkCmd = &cobra.Command{ } else { qrterminal.Generate(message.Data.URI, qrterminal.M, os.Stdout) } - break case "linking_successful": if !uriOrQR { fmt.Println("Successfully linked") os.Exit(0) } - break } } } diff --git a/cmd/signald-cli/cmd/listAccounts.go b/cmd/signald-cli/cmd/listAccounts.go index e856e15..1b5b5f8 100644 --- a/cmd/signald-cli/cmd/listAccounts.go +++ b/cmd/signald-cli/cmd/listAccounts.go @@ -17,6 +17,7 @@ package cmd import ( "fmt" + "log" "math/rand" "github.com/spf13/cobra" @@ -31,10 +32,13 @@ var listAccountsCmd = &cobra.Command{ Long: `Prints a list of all users to stdout.`, Run: func(cmd *cobra.Command, args []string) { requestID := fmt.Sprint("signald-cli-", rand.Intn(1000)) - s.SendRequest(signald.Request{ - Type: "list_accounts", - ID: requestID, + err := s.SendRequest(signald.Request{ + Type: "list_accounts", + ID: requestID, }) + if err != nil { + log.Fatal("error sending request: ", err) + } c := make(chan signald.Response) go s.Listen(c) diff --git a/cmd/signald-cli/cmd/listGroups.go b/cmd/signald-cli/cmd/listGroups.go index e455b84..7e6f934 100644 --- a/cmd/signald-cli/cmd/listGroups.go +++ b/cmd/signald-cli/cmd/listGroups.go @@ -17,6 +17,7 @@ package cmd import ( "fmt" + "log" "math/rand" "github.com/spf13/cobra" @@ -31,11 +32,14 @@ var listGroupsCmd = &cobra.Command{ Long: `Prints a list of all groups the user is in to stdout.`, Run: func(cmd *cobra.Command, args []string) { requestID := fmt.Sprint("signald-cli-", rand.Intn(1000)) - s.SendRequest(signald.Request{ + err := s.SendRequest(signald.Request{ Type: "list_groups", Username: username, ID: requestID, }) + if err != nil { + log.Fatal("error sending request: ", err) + } c := make(chan signald.Response) go s.Listen(c) @@ -55,5 +59,5 @@ func init() { RootCmd.AddCommand(listGroupsCmd) listGroupsCmd.Flags().StringVarP(&username, "username", "u", "", "The username of the account to use)") - listGroupsCmd.MarkFlagRequired("username") + must(listGroupsCmd.MarkFlagRequired("username")) } diff --git a/cmd/signald-cli/cmd/root.go b/cmd/signald-cli/cmd/root.go index a943e55..0d2c569 100644 --- a/cmd/signald-cli/cmd/root.go +++ b/cmd/signald-cli/cmd/root.go @@ -73,3 +73,9 @@ func initConfig() { fmt.Println("Using config file:", viper.ConfigFileUsed()) } } + +func must(err error) { + if err != nil { + log.Fatal(err) + } +} diff --git a/cmd/signald-cli/cmd/send.go b/cmd/signald-cli/cmd/send.go index a6132bd..9f93bc2 100644 --- a/cmd/signald-cli/cmd/send.go +++ b/cmd/signald-cli/cmd/send.go @@ -59,7 +59,10 @@ var sendCmd = &cobra.Command{ if attachment != "" { request.AttachmentFilenames = []string{attachment} } - s.SendRequest(request) + err := s.SendRequest(request) + if err != nil { + log.Fatal("error sending request: ", err) + } timeout := 10 @@ -81,7 +84,7 @@ func init() { RootCmd.AddCommand(sendCmd) sendCmd.Flags().StringVarP(&username, "username", "u", "", "The username to send from (required)") - sendCmd.MarkFlagRequired("username") + must(sendCmd.MarkFlagRequired("username")) sendCmd.Flags().StringVarP(&toUser, "to", "t", "", "The user to send the message to (cannot be combined with --group)") diff --git a/signald/signald.go b/signald/signald.go index 6e97b11..b7f0848 100644 --- a/signald/signald.go +++ b/signald/signald.go @@ -27,12 +27,6 @@ type Signald struct { SocketPath string } -func crash(err error) { - if err != nil { - panic(err) - } -} - // Connect connects to the signad socket func (s *Signald) Connect() error { if s.SocketPath == "" { @@ -48,7 +42,7 @@ func (s *Signald) Connect() error { } // Listen listens for events from signald -func (s *Signald) Listen(c chan Response) error { +func (s *Signald) Listen(c chan Response) { // we create a decoder that reads directly from the socket d := json.NewDecoder(s.socket) @@ -56,7 +50,7 @@ func (s *Signald) Listen(c chan Response) error { for { if err := d.Decode(&msg); err != nil { - return err + log.Println("error decoding message from signald:", err) } c <- msg }