ran go-fmt on complete sourcecode

This commit is contained in:
Bernhard B
2022-04-01 19:08:07 +02:00
parent d34fcb905e
commit 0b6bd44838
5 changed files with 30 additions and 32 deletions

View File

@@ -3,10 +3,10 @@ package api
import ( import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"errors"
"net/http" "net/http"
"strconv" "strconv"
"time" "time"
"errors"
"github.com/gabriel-vasile/mimetype" "github.com/gabriel-vasile/mimetype"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
@@ -29,9 +29,9 @@ const (
) )
type UpdateContactRequest struct { type UpdateContactRequest struct {
Recipient string `json:"recipient"` Recipient string `json:"recipient"`
Name *string `json:"name"` Name *string `json:"name"`
ExpirationInSeconds *int `json:"expiration_in_seconds"` ExpirationInSeconds *int `json:"expiration_in_seconds"`
} }
type GroupPermissions struct { type GroupPermissions struct {
@@ -48,11 +48,11 @@ type CreateGroupRequest struct {
} }
type ChangeGroupMembersRequest struct { type ChangeGroupMembersRequest struct {
Members []string `json:"members"` Members []string `json:"members"`
} }
type ChangeGroupAdminsRequest struct { type ChangeGroupAdminsRequest struct {
Admins []string `json:"admins"` Admins []string `json:"admins"`
} }
type LoggingConfiguration struct { type LoggingConfiguration struct {
@@ -360,7 +360,7 @@ func (a *Api) handleSignalReceive(ws *websocket.Conn, number string, stop chan s
for { for {
select { select {
case <-stop: case <-stop:
ws.Close() ws.Close()
return return
case msg := <-receiveChannel: case msg := <-receiveChannel:
@@ -1351,7 +1351,6 @@ func (a *Api) SearchForNumbers(c *gin.Context) {
c.JSON(200, searchResponse) c.JSON(200, searchResponse)
} }
// @Summary Updates the info associated to a number on the contact list. If the contact doesnt exist yet, it will be added. // @Summary Updates the info associated to a number on the contact list. If the contact doesnt exist yet, it will be added.
// @Tags Contacts // @Tags Contacts
// @Description Updates the info associated to a number on the contact list. // @Description Updates the info associated to a number on the contact list.

View File

@@ -123,8 +123,8 @@ type About struct {
} }
type SearchResultEntry struct { type SearchResultEntry struct {
Number string `json:"number"` Number string `json:"number"`
Registered bool `json:"registered"` Registered bool `json:"registered"`
} }
func cleanupTmpFiles(paths []string) { func cleanupTmpFiles(paths []string) {
@@ -470,7 +470,7 @@ func (s *SignalClient) send(number string, message string,
func (s *SignalClient) About() About { func (s *SignalClient) About() About {
about := About{SupportedApiVersions: []string{"v1", "v2"}, BuildNr: 2, Mode: getSignalCliModeString(s.signalCliMode), 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 return about
} }
@@ -533,7 +533,7 @@ func (s *SignalClient) getJsonRpc2Client(number string) (*JsonRpc2Client, error)
return nil, errors.New("Number not registered with JSON-RPC") return nil, errors.New("Number not registered with JSON-RPC")
} }
func (s *SignalClient) getJsonRpc2Clients() ([]*JsonRpc2Client) { func (s *SignalClient) getJsonRpc2Clients() []*JsonRpc2Client {
jsonRpc2Clients := []*JsonRpc2Client{} jsonRpc2Clients := []*JsonRpc2Client{}
for _, client := range s.jsonRpc2Clients { for _, client := range s.jsonRpc2Clients {
jsonRpc2Clients = append(jsonRpc2Clients, client) jsonRpc2Clients = append(jsonRpc2Clients, client)
@@ -709,10 +709,10 @@ func (s *SignalClient) updateGroupMembers(number string, groupId string, members
if s.signalCliMode == JsonRpc { if s.signalCliMode == JsonRpc {
type Request struct { type Request struct {
Name string `json:"name,omitempty"` Name string `json:"name,omitempty"`
Members []string `json:"member,omitempty"` Members []string `json:"member,omitempty"`
RemoveMembers []string `json:"remove-member,omitempty"` RemoveMembers []string `json:"remove-member,omitempty"`
GroupId string `json:"groupId"` GroupId string `json:"groupId"`
} }
request := Request{GroupId: internalGroupId} request := Request{GroupId: internalGroupId}
if add { if add {
@@ -772,10 +772,10 @@ func (s *SignalClient) updateGroupAdmins(number string, groupId string, admins [
if s.signalCliMode == JsonRpc { if s.signalCliMode == JsonRpc {
type Request struct { type Request struct {
Name string `json:"name,omitempty"` Name string `json:"name,omitempty"`
Admins []string `json:"admin,omitempty"` Admins []string `json:"admin,omitempty"`
RemoveAdmins []string `json:"remove-admin,omitempty"` RemoveAdmins []string `json:"remove-admin,omitempty"`
GroupId string `json:"groupId"` GroupId string `json:"groupId"`
} }
request := Request{GroupId: internalGroupId} request := Request{GroupId: internalGroupId}
if add { if add {
@@ -1367,9 +1367,9 @@ func (s *SignalClient) UpdateContact(number string, recipient string, name *stri
var err error var err error
if s.signalCliMode == JsonRpc { if s.signalCliMode == JsonRpc {
type Request struct { type Request struct {
Recipient string `json:"recipient"` Recipient string `json:"recipient"`
Name string `json:"name,omitempty"` Name string `json:"name,omitempty"`
Expiration int `json:"expiration,omitempty"` Expiration int `json:"expiration,omitempty"`
} }
request := Request{Recipient: recipient} request := Request{Recipient: recipient}
if name != nil { if name != nil {

View File

@@ -101,7 +101,7 @@ func (r *JsonRpc2Client) ReceiveData(number string) {
str, err := connbuf.ReadString('\n') str, err := connbuf.ReadString('\n')
if err != nil { if err != nil {
elapsed := time.Since(r.lastTimeErrorMessageSent) 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?") log.Error("Couldn't read data for number ", number, ": ", err.Error(), ". Is the number properly registered?")
r.lastTimeErrorMessageSent = time.Now() r.lastTimeErrorMessageSent = time.Now()
} }

View File

@@ -1,8 +1,10 @@
package main package main
import ( import (
"encoding/json"
"fmt" "fmt"
"github.com/bbernhard/signal-cli-rest-api/utils" "github.com/bbernhard/signal-cli-rest-api/utils"
"github.com/gabriel-vasile/mimetype"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"io/ioutil" "io/ioutil"
"os" "os"
@@ -10,8 +12,6 @@ import (
"path/filepath" "path/filepath"
"strconv" "strconv"
"strings" "strings"
"github.com/gabriel-vasile/mimetype"
"encoding/json"
) )
const supervisorctlConfigTemplate = ` const supervisorctlConfigTemplate = `
@@ -48,7 +48,6 @@ func isSignalCliLinkedNumberConfigFile(filename string) (bool, error) {
return false, nil return false, nil
} }
func getUsernameFromLinkedNumberConfigFile(filename string) (string, error) { func getUsernameFromLinkedNumberConfigFile(filename string) (string, error) {
type LinkedNumberConfigFile struct { type LinkedNumberConfigFile struct {
Username string `json:"username"` Username string `json:"username"`
@@ -126,7 +125,7 @@ func main() {
uid := utils.GetEnv("SIGNAL_CLI_UID", "1000") uid := utils.GetEnv("SIGNAL_CLI_UID", "1000")
gid := utils.GetEnv("SIGNAL_CLI_GID", "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 { if err != nil {
log.Fatal("Couldn't change permissions of fifo with name ", fifoPathname, ": ", err.Error()) log.Fatal("Couldn't change permissions of fifo with name ", fifoPathname, ": ", err.Error())
} }

View File

@@ -24,12 +24,12 @@ func GetIntEnv(key string, defaultVal int) (int, error) {
} }
func StringInSlice(a string, list []string) bool { func StringInSlice(a string, list []string) bool {
for _, b := range list { for _, b := range list {
if b == a { if b == a {
return true return true
} }
} }
return false return false
} }
func IsPhoneNumber(s string) bool { func IsPhoneNumber(s string) bool {