Fix the CI linting job and all repoted issues

This commit is contained in:
Finn 2020-11-22 00:26:30 -08:00
parent 0b93eb536c
commit 6fccb53b2a
7 changed files with 34 additions and 23 deletions

View file

@ -1,16 +1,16 @@
stages: stages:
- lint
- build - build
lint: lint:
image: golang:latest image: nixery.dev/shell/go/golangci-lint
stage: lint stage: build
before_script: 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 - mkdir -p /go/src/git.callpipe.com/finn/signald-go
- cp -r * /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 - cd /go/src/git.callpipe.com/finn/signald-go
script: script:
- gofmt -d . - golangci-lint run
build: build:
stage: build stage: build

View file

@ -36,10 +36,13 @@ var linkCmd = &cobra.Command{
Long: `Get a URI or QR code to link to an existing Signal account`, Long: `Get a URI or QR code to link to an existing Signal account`,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
requestID := fmt.Sprint("signald-cli-", rand.Intn(1000)) requestID := fmt.Sprint("signald-cli-", rand.Intn(1000))
s.SendRequest(signald.Request{ err := s.SendRequest(signald.Request{
Type: "link", Type: "link",
ID: requestID, ID: requestID,
}) })
if err != nil {
log.Fatal("error sending request: ", err)
}
c := make(chan signald.Response) c := make(chan signald.Response)
go s.Listen(c) go s.Listen(c)
@ -50,7 +53,6 @@ var linkCmd = &cobra.Command{
case "linking_error": case "linking_error":
log.Fatal(message.Data.Message) log.Fatal(message.Data.Message)
os.Exit(1) os.Exit(1)
break
case "linking_uri": case "linking_uri":
if uriOrQR { if uriOrQR {
@ -58,14 +60,12 @@ var linkCmd = &cobra.Command{
} else { } else {
qrterminal.Generate(message.Data.URI, qrterminal.M, os.Stdout) qrterminal.Generate(message.Data.URI, qrterminal.M, os.Stdout)
} }
break
case "linking_successful": case "linking_successful":
if !uriOrQR { if !uriOrQR {
fmt.Println("Successfully linked") fmt.Println("Successfully linked")
os.Exit(0) os.Exit(0)
} }
break
} }
} }
} }

View file

@ -17,6 +17,7 @@ package cmd
import ( import (
"fmt" "fmt"
"log"
"math/rand" "math/rand"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -31,10 +32,13 @@ var listAccountsCmd = &cobra.Command{
Long: `Prints a list of all users to stdout.`, Long: `Prints a list of all users to stdout.`,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
requestID := fmt.Sprint("signald-cli-", rand.Intn(1000)) requestID := fmt.Sprint("signald-cli-", rand.Intn(1000))
s.SendRequest(signald.Request{ err := s.SendRequest(signald.Request{
Type: "list_accounts", Type: "list_accounts",
ID: requestID, ID: requestID,
}) })
if err != nil {
log.Fatal("error sending request: ", err)
}
c := make(chan signald.Response) c := make(chan signald.Response)
go s.Listen(c) go s.Listen(c)

View file

@ -17,6 +17,7 @@ package cmd
import ( import (
"fmt" "fmt"
"log"
"math/rand" "math/rand"
"github.com/spf13/cobra" "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.`, Long: `Prints a list of all groups the user is in to stdout.`,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
requestID := fmt.Sprint("signald-cli-", rand.Intn(1000)) requestID := fmt.Sprint("signald-cli-", rand.Intn(1000))
s.SendRequest(signald.Request{ err := s.SendRequest(signald.Request{
Type: "list_groups", Type: "list_groups",
Username: username, Username: username,
ID: requestID, ID: requestID,
}) })
if err != nil {
log.Fatal("error sending request: ", err)
}
c := make(chan signald.Response) c := make(chan signald.Response)
go s.Listen(c) go s.Listen(c)
@ -55,5 +59,5 @@ func init() {
RootCmd.AddCommand(listGroupsCmd) RootCmd.AddCommand(listGroupsCmd)
listGroupsCmd.Flags().StringVarP(&username, "username", "u", "", "The username of the account to use)") listGroupsCmd.Flags().StringVarP(&username, "username", "u", "", "The username of the account to use)")
listGroupsCmd.MarkFlagRequired("username") must(listGroupsCmd.MarkFlagRequired("username"))
} }

View file

@ -73,3 +73,9 @@ func initConfig() {
fmt.Println("Using config file:", viper.ConfigFileUsed()) fmt.Println("Using config file:", viper.ConfigFileUsed())
} }
} }
func must(err error) {
if err != nil {
log.Fatal(err)
}
}

View file

@ -59,7 +59,10 @@ var sendCmd = &cobra.Command{
if attachment != "" { if attachment != "" {
request.AttachmentFilenames = []string{attachment} request.AttachmentFilenames = []string{attachment}
} }
s.SendRequest(request) err := s.SendRequest(request)
if err != nil {
log.Fatal("error sending request: ", err)
}
timeout := 10 timeout := 10
@ -81,7 +84,7 @@ func init() {
RootCmd.AddCommand(sendCmd) RootCmd.AddCommand(sendCmd)
sendCmd.Flags().StringVarP(&username, "username", "u", "", "The username to send from (required)") 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)") sendCmd.Flags().StringVarP(&toUser, "to", "t", "", "The user to send the message to (cannot be combined with --group)")

View file

@ -27,12 +27,6 @@ type Signald struct {
SocketPath string SocketPath string
} }
func crash(err error) {
if err != nil {
panic(err)
}
}
// Connect connects to the signad socket // Connect connects to the signad socket
func (s *Signald) Connect() error { func (s *Signald) Connect() error {
if s.SocketPath == "" { if s.SocketPath == "" {
@ -48,7 +42,7 @@ func (s *Signald) Connect() error {
} }
// Listen listens for events from signald // 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 // we create a decoder that reads directly from the socket
d := json.NewDecoder(s.socket) d := json.NewDecoder(s.socket)
@ -56,7 +50,7 @@ func (s *Signald) Listen(c chan Response) error {
for { for {
if err := d.Decode(&msg); err != nil { if err := d.Decode(&msg); err != nil {
return err log.Println("error decoding message from signald:", err)
} }
c <- msg c <- msg
} }