Fix the CI linting job and all repoted issues
This commit is contained in:
parent
0b93eb536c
commit
6fccb53b2a
7 changed files with 34 additions and 23 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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"))
|
||||
}
|
||||
|
|
|
@ -73,3 +73,9 @@ func initConfig() {
|
|||
fmt.Println("Using config file:", viper.ConfigFileUsed())
|
||||
}
|
||||
}
|
||||
|
||||
func must(err error) {
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)")
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue