diff --git a/src/api/api.go b/src/api/api.go index 9aec337..74dfa19 100644 --- a/src/api/api.go +++ b/src/api/api.go @@ -3,10 +3,10 @@ package api import ( "bytes" "encoding/json" + "errors" "net/http" "strconv" "time" - "errors" "github.com/gabriel-vasile/mimetype" "github.com/gin-gonic/gin" @@ -29,9 +29,9 @@ const ( ) type UpdateContactRequest struct { - Recipient string `json:"recipient"` - Name *string `json:"name"` - ExpirationInSeconds *int `json:"expiration_in_seconds"` + Recipient string `json:"recipient"` + Name *string `json:"name"` + ExpirationInSeconds *int `json:"expiration_in_seconds"` } type GroupPermissions struct { @@ -48,11 +48,11 @@ type CreateGroupRequest struct { } type ChangeGroupMembersRequest struct { - Members []string `json:"members"` + Members []string `json:"members"` } type ChangeGroupAdminsRequest struct { - Admins []string `json:"admins"` + Admins []string `json:"admins"` } type LoggingConfiguration struct { @@ -360,7 +360,7 @@ func (a *Api) handleSignalReceive(ws *websocket.Conn, number string, stop chan s for { select { - case <-stop: + case <-stop: ws.Close() return case msg := <-receiveChannel: @@ -1351,7 +1351,6 @@ func (a *Api) SearchForNumbers(c *gin.Context) { c.JSON(200, searchResponse) } - // @Summary Updates the info associated to a number on the contact list. If the contact doesn’t exist yet, it will be added. // @Tags Contacts // @Description Updates the info associated to a number on the contact list. diff --git a/src/client/client.go b/src/client/client.go index c2c13f2..edb17e5 100644 --- a/src/client/client.go +++ b/src/client/client.go @@ -123,8 +123,8 @@ type About struct { } type SearchResultEntry struct { - Number string `json:"number"` - Registered bool `json:"registered"` + Number string `json:"number"` + Registered bool `json:"registered"` } func cleanupTmpFiles(paths []string) { @@ -470,7 +470,7 @@ func (s *SignalClient) send(number string, message string, func (s *SignalClient) About() About { about := About{SupportedApiVersions: []string{"v1", "v2"}, BuildNr: 2, Mode: getSignalCliModeString(s.signalCliMode), - Version: utils.GetEnv("BUILD_VERSION", "unset")} + Version: utils.GetEnv("BUILD_VERSION", "unset")} return about } @@ -533,7 +533,7 @@ func (s *SignalClient) getJsonRpc2Client(number string) (*JsonRpc2Client, error) return nil, errors.New("Number not registered with JSON-RPC") } -func (s *SignalClient) getJsonRpc2Clients() ([]*JsonRpc2Client) { +func (s *SignalClient) getJsonRpc2Clients() []*JsonRpc2Client { jsonRpc2Clients := []*JsonRpc2Client{} for _, client := range s.jsonRpc2Clients { jsonRpc2Clients = append(jsonRpc2Clients, client) @@ -709,10 +709,10 @@ func (s *SignalClient) updateGroupMembers(number string, groupId string, members if s.signalCliMode == JsonRpc { type Request struct { - Name string `json:"name,omitempty"` - Members []string `json:"member,omitempty"` + Name string `json:"name,omitempty"` + Members []string `json:"member,omitempty"` RemoveMembers []string `json:"remove-member,omitempty"` - GroupId string `json:"groupId"` + GroupId string `json:"groupId"` } request := Request{GroupId: internalGroupId} if add { @@ -772,10 +772,10 @@ func (s *SignalClient) updateGroupAdmins(number string, groupId string, admins [ if s.signalCliMode == JsonRpc { type Request struct { - Name string `json:"name,omitempty"` - Admins []string `json:"admin,omitempty"` + Name string `json:"name,omitempty"` + Admins []string `json:"admin,omitempty"` RemoveAdmins []string `json:"remove-admin,omitempty"` - GroupId string `json:"groupId"` + GroupId string `json:"groupId"` } request := Request{GroupId: internalGroupId} if add { @@ -1367,9 +1367,9 @@ func (s *SignalClient) UpdateContact(number string, recipient string, name *stri var err error if s.signalCliMode == JsonRpc { type Request struct { - Recipient string `json:"recipient"` - Name string `json:"name,omitempty"` - Expiration int `json:"expiration,omitempty"` + Recipient string `json:"recipient"` + Name string `json:"name,omitempty"` + Expiration int `json:"expiration,omitempty"` } request := Request{Recipient: recipient} if name != nil { diff --git a/src/client/jsonrpc2.go b/src/client/jsonrpc2.go index aa4a073..9c86200 100644 --- a/src/client/jsonrpc2.go +++ b/src/client/jsonrpc2.go @@ -101,7 +101,7 @@ func (r *JsonRpc2Client) ReceiveData(number string) { str, err := connbuf.ReadString('\n') if err != nil { elapsed := time.Since(r.lastTimeErrorMessageSent) - if(elapsed) > time.Duration(5*time.Minute) { //avoid spamming the log file and only log the message at max every 5 minutes + if (elapsed) > time.Duration(5*time.Minute) { //avoid spamming the log file and only log the message at max every 5 minutes log.Error("Couldn't read data for number ", number, ": ", err.Error(), ". Is the number properly registered?") r.lastTimeErrorMessageSent = time.Now() } diff --git a/src/scripts/jsonrpc2-helper.go b/src/scripts/jsonrpc2-helper.go index 09c1fc9..5ac288c 100644 --- a/src/scripts/jsonrpc2-helper.go +++ b/src/scripts/jsonrpc2-helper.go @@ -1,8 +1,10 @@ package main import ( + "encoding/json" "fmt" "github.com/bbernhard/signal-cli-rest-api/utils" + "github.com/gabriel-vasile/mimetype" log "github.com/sirupsen/logrus" "io/ioutil" "os" @@ -10,8 +12,6 @@ import ( "path/filepath" "strconv" "strings" - "github.com/gabriel-vasile/mimetype" - "encoding/json" ) const supervisorctlConfigTemplate = ` @@ -48,7 +48,6 @@ func isSignalCliLinkedNumberConfigFile(filename string) (bool, error) { return false, nil } - func getUsernameFromLinkedNumberConfigFile(filename string) (string, error) { type LinkedNumberConfigFile struct { Username string `json:"username"` @@ -126,7 +125,7 @@ func main() { uid := utils.GetEnv("SIGNAL_CLI_UID", "1000") gid := utils.GetEnv("SIGNAL_CLI_GID", "1000") - _, err = exec.Command("chown", uid + ":" + gid, fifoPathname).Output() + _, err = exec.Command("chown", uid+":"+gid, fifoPathname).Output() if err != nil { log.Fatal("Couldn't change permissions of fifo with name ", fifoPathname, ": ", err.Error()) } diff --git a/src/utils/utils.go b/src/utils/utils.go index 70612bd..f0e87c2 100644 --- a/src/utils/utils.go +++ b/src/utils/utils.go @@ -24,12 +24,12 @@ func GetIntEnv(key string, defaultVal int) (int, error) { } func StringInSlice(a string, list []string) bool { - for _, b := range list { - if b == a { - return true - } - } - return false + for _, b := range list { + if b == a { + return true + } + } + return false } func IsPhoneNumber(s string) bool {