From bfb5e28a03b0aced64af3ca4ad81813544a76799 Mon Sep 17 00:00:00 2001 From: Martin Dosch Date: Mon, 25 Apr 2022 21:29:14 +0200 Subject: [PATCH] Change variable names and error strings [golint]. --- const.go | 4 ++-- httpupload.go | 26 +++++++++++++------------- main.go | 16 ++++++++-------- ox.go | 32 ++++++++++++++++---------------- parseconfig.go | 2 +- 5 files changed, 40 insertions(+), 40 deletions(-) diff --git a/const.go b/const.go index 4717ad8..d7f151e 100644 --- a/const.go +++ b/const.go @@ -5,10 +5,10 @@ package main const ( - VERSION = "0.4.0-devel" + version = "0.4.0-devel" nsEme = "urn:xmpp:eme:0" nsHints = "urn:xmpp:hints" - nsHttpUpload = "urn:xmpp:http:upload:0" + nsHTTPUpload = "urn:xmpp:http:upload:0" nsJabberClient = "jabber:client" nsJabberData = "jabber:x:data" nsOx = "urn:xmpp:openpgp:0" diff --git a/httpupload.go b/httpupload.go index 624dd34..f1554b9 100644 --- a/httpupload.go +++ b/httpupload.go @@ -103,7 +103,7 @@ func httpUpload(client *xmpp.Client, jserver string, filePath string) string { varAttr := t.SelectAttr("var") prevFieldVal := field[i-1].SelectElement("value") curFieldVal := t.SelectElement("value") - if varAttr.Value == "max-file-size" && prevFieldVal.Text() == nsHttpUpload { + if varAttr.Value == "max-file-size" && prevFieldVal.Text() == nsHTTPUpload { maxFileSize, err = strconv.ParseInt(curFieldVal.Text(), 10, 64) if err != nil { log.Fatal("Error while checking server maximum http upload file size.") @@ -124,7 +124,7 @@ func httpUpload(client *xmpp.Client, jserver string, filePath string) string { request := etree.NewDocument() requestReq := request.CreateElement("request") - requestReq.CreateAttr("xmlns", nsHttpUpload) + requestReq.CreateAttr("xmlns", nsHTTPUpload) requestReq.CreateAttr("filename", fileNameEscaped) requestReq.CreateAttr("size", fmt.Sprint(fileSize)) requestReq.CreateAttr("content-type", mimeType) @@ -141,25 +141,25 @@ func httpUpload(client *xmpp.Client, jserver string, filePath string) string { if uploadSlot.Type != "result" { log.Fatal("Error while requesting upload slot.") } - iqHttpUploadSlotXML := etree.NewDocument() - err = iqHttpUploadSlotXML.ReadFromBytes(uploadSlot.Query) + iqHTTPUploadSlotXML := etree.NewDocument() + err = iqHTTPUploadSlotXML.ReadFromBytes(uploadSlot.Query) if err != nil { log.Fatal(err) } - iqHttpUploadSlotXMLSlot := iqHttpUploadSlotXML.SelectElement("slot") - iqHttpUploadSlotXMLPut := iqHttpUploadSlotXMLSlot.SelectElement("put") - iqHttpUploadSlotXMLPutURL := iqHttpUploadSlotXMLPut.SelectAttr("url") + iqHTTPUploadSlotXMLSlot := iqHTTPUploadSlotXML.SelectElement("slot") + iqHTTPUploadSlotXMLPut := iqHTTPUploadSlotXMLSlot.SelectElement("put") + iqHTTPUploadSlotXMLPutURL := iqHTTPUploadSlotXMLPut.SelectAttr("url") // Upload file httpClient := &http.Client{} - req, err := http.NewRequest(http.MethodPut, iqHttpUploadSlotXMLPutURL.Value, + req, err := http.NewRequest(http.MethodPut, iqHTTPUploadSlotXMLPutURL.Value, buffer) if err != nil { log.Fatal(err) } req.Header.Set("Content-Type", mimeTypeEscaped.String()) - iqHttpUploadSlotXMLPutHeaders := iqHttpUploadSlotXMLPut.SelectElements("header") - for _, h := range iqHttpUploadSlotXMLPutHeaders { + iqHTTPUploadSlotXMLPutHeaders := iqHTTPUploadSlotXMLPut.SelectElements("header") + for _, h := range iqHTTPUploadSlotXMLPutHeaders { name := h.SelectAttr("name") switch name.Value { case "Authorization", "Cookie", "Expires": @@ -176,7 +176,7 @@ func httpUpload(client *xmpp.Client, jserver string, filePath string) string { } // Return http link - iqHttpUploadSlotXMLGet := iqHttpUploadSlotXMLSlot.SelectElement("get") - iqHttpUploadSlotXMLGetURL := iqHttpUploadSlotXMLGet.SelectAttr("url") - return iqHttpUploadSlotXMLGetURL.Value + iqHTTPUploadSlotXMLGet := iqHTTPUploadSlotXMLSlot.SelectElement("get") + iqHTTPUploadSlotXMLGetURL := iqHTTPUploadSlotXMLGet.SelectAttr("url") + return iqHTTPUploadSlotXMLGetURL.Value } diff --git a/main.go b/main.go index 524e9cd..eb32535 100644 --- a/main.go +++ b/main.go @@ -84,7 +84,7 @@ func main() { // Define command line flags. flagHelp := getopt.BoolLong("help", 0, "Show help.") - flagHttpUpload := getopt.StringLong("http-upload", 0, "", "Send a file via http-upload.") + flagHTTPUpload := getopt.StringLong("http-upload", 0, "", "Send a file via http-upload.") flagDebug := getopt.BoolLong("debug", 'd', "Show debugging info.") flagServer := getopt.StringLong("jserver", 'j', "", "XMPP server address.") flagUser := getopt.StringLong("username", 'u', "", "Username for XMPP account.") @@ -124,21 +124,21 @@ func main() { os.Exit(0) case *flagVersion: // If requested, show version and quit. - fmt.Println("go-sendxmpp", VERSION) + fmt.Println("go-sendxmpp", version) fmt.Println("License: BSD-2-clause") os.Exit(0) // Quit if Ox (OpenPGP for XMPP) is requested for unsupported operations like // groupchat, http-upload or listening. - case *flagOx && *flagHttpUpload != "": + case *flagOx && *flagHTTPUpload != "": log.Fatal("No Ox support for http-upload available.") case *flagOx && *flagChatroom: log.Fatal("No Ox support for chat rooms available.") case *flagOx && *flagListen: log.Fatal("No Ox support for receiving messages available.") - case *flagHttpUpload != "" && *flagInteractive: + case *flagHTTPUpload != "" && *flagInteractive: log.Fatal("Interactive mode and http upload can't" + " be used at the same time.") - case *flagHttpUpload != "" && *flagMessageFile != "": + case *flagHTTPUpload != "" && *flagMessageFile != "": log.Fatal("You can't send a message while using" + " http upload.") } @@ -302,9 +302,9 @@ func main() { } } - if *flagHttpUpload != "" { + if *flagHTTPUpload != "" { message = httpUpload(client, tlsConfig.ServerName, - *flagHttpUpload) + *flagHTTPUpload) } // Skip reading message if '-i' or '--interactive' is set to work with e.g. 'tail -f'. @@ -425,7 +425,7 @@ func main() { default: for _, recipient := range recipients { switch { - case *flagHttpUpload != "": + case *flagHTTPUpload != "": _, err = client.Send(xmpp.Chat{Remote: recipient.Jid, Type: msgType, Ooburl: message, Text: message}) if err != nil { diff --git a/ox.go b/ox.go index 0d208c4..1915ccc 100644 --- a/ox.go +++ b/ox.go @@ -19,7 +19,7 @@ import ( ) func oxImportPrivKey(jid string, privKeyLocation string, client *xmpp.Client) error { - xmppUri := "xmpp:" + jid + xmppURI := "xmpp:" + jid buffer, err := readFile(privKeyLocation) if err != nil { return err @@ -32,8 +32,8 @@ func oxImportPrivKey(jid string, privKeyLocation string, client *xmpp.Client) er } } entity := key.GetEntity() - if entity.Identities[xmppUri] == nil { - return errors.New("Key identity is not " + xmppUri) + if entity.Identities[xmppURI] == nil { + return errors.New("Key identity is not " + xmppURI) } pk, err := key.GetPublicKey() if err != nil { @@ -195,8 +195,8 @@ func oxStoreKey(location string, key string) error { } func oxGenPrivKey(jid string, client *xmpp.Client, passphrase string) error { - xmppUri := "xmpp:" + jid - key, err := crypto.GenerateKey(xmppUri, xmppUri, "x25519", 0) + xmppURI := "xmpp:" + jid + key, err := crypto.GenerateKey(xmppURI, xmppURI, "x25519", 0) if err != nil { return err } @@ -263,20 +263,20 @@ func oxGenPrivKey(jid string, client *xmpp.Client, passphrase string) error { return err } if iqReply.Type != "result" { - return errors.New("Error while publishing public key.") + return errors.New("Error while publishing public key") } ownPubKeyRingFromPubsub, err := oxRecvPublicKeys(client, jid, fingerprint) if err != nil { - return errors.New("Couldn't successfully verify public key upload.") + return errors.New("Couldn't successfully verify public key upload") } ownPubKeyFromPubsub := ownPubKeyRingFromPubsub.GetKeys()[0] ownPubKeyFromPubsubSerialized, err := ownPubKeyFromPubsub.Serialize() if err != nil { - return errors.New("Couldn't successfully verify public key upload.") + return errors.New("Couldn't successfully verify public key upload") } if pubKeyBase64 != base64.StdEncoding.EncodeToString(ownPubKeyFromPubsubSerialized) { - return errors.New("Couldn't successfully verify public key upload.") + return errors.New("Couldn't successfully verify public key upload") } root = etree.NewDocument() @@ -312,7 +312,7 @@ func oxGenPrivKey(jid string, client *xmpp.Client, passphrase string) error { return err } if iqReply.Type != "result" { - return errors.New("Couldn't publish public key list.") + return errors.New("Couldn't publish public key list") } return nil } @@ -401,7 +401,7 @@ func oxGetPublicKeyRing(client *xmpp.Client, recipient string) (*crypto.KeyRing, return nil, err } - pubKeyRingId := "none" + pubKeyRingID := "none" newestKey, err := time.Parse(time.RFC3339, "1900-01-01T00:00:00Z") if err != nil { return nil, err @@ -422,14 +422,14 @@ func oxGetPublicKeyRing(client *xmpp.Client, recipient string) (*crypto.KeyRing, } if keyDate.After(newestKey) { newestKey = keyDate - pubKeyRingId = fingerprint.Value + pubKeyRingID = fingerprint.Value } } - if pubKeyRingId == "none" { + if pubKeyRingID == "none" { return nil, errors.New("server didn't provide public key fingerprints for " + recipient) } - pubKeyRingLocation, err := oxGetPubKeyLoc(pubKeyRingId) + pubKeyRingLocation, err := oxGetPubKeyLoc(pubKeyRingID) if err != nil { return nil, err } @@ -446,7 +446,7 @@ func oxGetPublicKeyRing(client *xmpp.Client, recipient string) (*crypto.KeyRing, if !savedKeysDate.Before(newestKey) { pubKeys := pubKeyReadXML.SelectElements("pubkey") if pubKeys == nil { - return nil, errors.New("Couldn't read public keys from cache.") + return nil, errors.New("Couldn't read public keys from cache") } for _, r := range pubKeys { keyByte, err := base64.StdEncoding.DecodeString(r.Text()) @@ -470,7 +470,7 @@ func oxGetPublicKeyRing(client *xmpp.Client, recipient string) (*crypto.KeyRing, } } } - pubKeyRing, err := oxRecvPublicKeys(client, recipient, pubKeyRingId) + pubKeyRing, err := oxRecvPublicKeys(client, recipient, pubKeyRingID) if err != nil { return nil, err } diff --git a/parseconfig.go b/parseconfig.go index 54574da..87b1c8a 100644 --- a/parseconfig.go +++ b/parseconfig.go @@ -42,7 +42,7 @@ func findConfig() (string, error) { return r, nil } } - return "", errors.New("no configuration file found.") + return "", errors.New("no configuration file found") } // Opens the config file and returns the specified values