From ec9bc9b7520a8e8c3c372943126df985329dcd18 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Sun, 23 Feb 2020 20:24:50 +0100 Subject: go fmt --- appservice/account.go | 18 ++++++------- appservice/db.go | 2 +- connector/connector.go | 8 +++--- connector/mattermost/mattermost.go | 35 ++++++++++++------------ connector/mediaobject.go | 21 ++++++++------- connector/xmpp/xmpp.go | 55 +++++++++++++++++++------------------- main.go | 4 +-- mxlib/client.go | 30 ++++++++++----------- mxlib/mediaobject.go | 16 +++++------ mxlib/registration.go | 2 +- 10 files changed, 95 insertions(+), 96 deletions(-) diff --git a/appservice/account.go b/appservice/account.go index f1f9d13..4bb2dfe 100644 --- a/appservice/account.go +++ b/appservice/account.go @@ -286,24 +286,24 @@ func (a *Account) eventInternal(event *Event) error { if err != nil { return err } - content := map[string]interface{} { - "body": mxfile.Filename(), + content := map[string]interface{}{ + "body": mxfile.Filename(), "filename": mxfile.Filename(), - "url": fmt.Sprintf("mxc://%s/%s", mxfile.MxcServer, mxfile.MxcMediaId), + "url": fmt.Sprintf("mxc://%s/%s", mxfile.MxcServer, mxfile.MxcMediaId), } if sz := mxfile.ImageSize(); sz != nil { content["msgtype"] = "m.image" - content["info"] = map[string]interface{} { + content["info"] = map[string]interface{}{ "mimetype": mxfile.Mimetype(), - "size": mxfile.Size(), - "w": sz.Width, - "h": sz.Height, + "size": mxfile.Size(), + "w": sz.Width, + "h": sz.Height, } } else { content["msgtype"] = "m.file" - content["info"] = map[string]interface{} { + content["info"] = map[string]interface{}{ "mimetype": mxfile.Mimetype(), - "size": mxfile.Size(), + "size": mxfile.Size(), } } err = mx.SendAs(mx_room_id, "m.room.message", content, mx_user_id) diff --git a/appservice/db.go b/appservice/db.go index 646dae3..9c3280c 100644 --- a/appservice/db.go +++ b/appservice/db.go @@ -41,7 +41,7 @@ func InitDb() error { type DbCache struct { gorm.Model - Key string `gorm:"unique_index"` + Key string `gorm:"unique_index"` Value string } diff --git a/connector/connector.go b/connector/connector.go index 3a2e20c..38ce828 100644 --- a/connector/connector.go +++ b/connector/connector.go @@ -136,12 +136,12 @@ type UserInfo struct { // If non-empty, the Filename of the avatar object will be used by Easybridge // to deduplicate the update events and prevent needless reuploads. // Example strategy that works for the mattermost backend: use the update timestamp as fictious file name - Avatar MediaObject + Avatar MediaObject } type RoomInfo struct { - Name string - Topic string + Name string + Topic string // Same deduplication comment as for UserInfo.Avatar Picture MediaObject @@ -164,6 +164,6 @@ type MediaObject interface { } type ImageSize struct { - Width int + Width int Height int } diff --git a/connector/mattermost/mattermost.go b/connector/mattermost/mattermost.go index 13deb6e..010e102 100644 --- a/connector/mattermost/mattermost.go +++ b/connector/mattermost/mattermost.go @@ -1,16 +1,16 @@ package mattermost import ( - "net/http" + "encoding/json" "fmt" + "io/ioutil" + "net/http" _ "os" "strings" "time" - "io/ioutil" - "encoding/json" - "github.com/mattermost/mattermost-server/model" "github.com/42wim/matterbridge/matterclient" + "github.com/mattermost/mattermost-server/model" log "github.com/sirupsen/logrus" . "git.deuxfleurs.fr/Deuxfleurs/easybridge/connector" @@ -22,19 +22,18 @@ import ( type Mattermost struct { handler Handler - server string + server string username string - teams map[string]bool + teams map[string]bool - conn *matterclient.MMClient + conn *matterclient.MMClient handlerStopChan chan bool - usermap map[string]string // map username to mm user id - sentjoinedmap map[string]bool // map username/room name to bool - userdisplaynamemap map[UserID]string // map username to last displayname + usermap map[string]string // map username to mm user id + sentjoinedmap map[string]bool // map username/room name to bool + userdisplaynamemap map[UserID]string // map username to last displayname } - func (mm *Mattermost) SetHandler(h Handler) { mm.handler = h } @@ -318,7 +317,7 @@ func (mm *Mattermost) handleConnected() { // Update room info room_info := &RoomInfo{ - Name: ch.DisplayName, + Name: ch.DisplayName, Topic: ch.Header, } for _, t := range mm.conn.OtherTeams { @@ -446,8 +445,8 @@ func (mm *Mattermost) ensureJoined(user *model.User, roomId RoomID) { if _, ok := mm.sentjoinedmap[cache_key]; !ok { mm.handler.Event(&Event{ Author: userId, - Room: roomId, - Type: EVENT_JOIN, + Room: roomId, + Type: EVENT_JOIN, }) mm.sentjoinedmap[cache_key] = true } @@ -484,10 +483,10 @@ func (mm *Mattermost) handlePost(channel_name string, post *model.Post, only_mes // Build message event msg_ev := &Event{ - Id: post.Id, + Id: post.Id, Author: userId, - Text: post.Message, - Type: EVENT_MESSAGE, + Text: post.Message, + Type: EVENT_MESSAGE, } if post.Type == "me" { msg_ev.Type = EVENT_ACTION @@ -511,7 +510,7 @@ func (mm *Mattermost) handlePost(channel_name string, post *model.Post, only_mes } if file.Width > 0 { media_object.ObjectImageSize = &ImageSize{ - Width: file.Width, + Width: file.Width, Height: file.Height, } } diff --git a/connector/mediaobject.go b/connector/mediaobject.go index 244e571..f904459 100644 --- a/connector/mediaobject.go +++ b/connector/mediaobject.go @@ -58,10 +58,10 @@ func (m *FileMediaObject) URL() string { // ---- type UrlMediaObject struct { - ObjectFilename string - ObjectSize int64 - ObjectMimetype string - ObjectURL string + ObjectFilename string + ObjectSize int64 + ObjectMimetype string + ObjectURL string ObjectImageSize *ImageSize } @@ -96,10 +96,10 @@ func (m *UrlMediaObject) URL() string { // ---- type BlobMediaObject struct { - ObjectFilename string - ObjectMimetype string + ObjectFilename string + ObjectMimetype string ObjectImageSize *ImageSize - ObjectData []byte + ObjectData []byte } func (m *BlobMediaObject) Filename() string { @@ -129,6 +129,7 @@ func (m *BlobMediaObject) URL() string { type nullCloseReader struct { io.Reader } + func (ncr nullCloseReader) Close() error { return nil } @@ -136,10 +137,10 @@ func (ncr nullCloseReader) Close() error { // ---- type LazyBlobMediaObject struct { - ObjectFilename string - ObjectMimetype string + ObjectFilename string + ObjectMimetype string ObjectImageSize *ImageSize - ObjectData []byte + ObjectData []byte GetFn func(o *LazyBlobMediaObject) error } diff --git a/connector/xmpp/xmpp.go b/connector/xmpp/xmpp.go index 02d1a96..7e35135 100644 --- a/connector/xmpp/xmpp.go +++ b/connector/xmpp/xmpp.go @@ -3,12 +3,12 @@ package xmpp import ( "time" //"os" - "strings" - "fmt" "crypto/tls" + "fmt" + "strings" - log "github.com/sirupsen/logrus" gxmpp "github.com/mattn/go-xmpp" + log "github.com/sirupsen/logrus" . "git.deuxfleurs.fr/Deuxfleurs/easybridge/connector" ) @@ -22,16 +22,16 @@ type XMPP struct { handler Handler connectorLoopNum int - connected bool - timeout int + connected bool + timeout int - server string - port int - ssl bool - jid string + server string + port int + ssl bool + jid string jid_localpart string - password string - nickname string + password string + nickname string conn *gxmpp.Client @@ -42,7 +42,7 @@ func (xm *XMPP) SetHandler(h Handler) { xm.handler = h } -func(xm *XMPP) Protocol() string { +func (xm *XMPP) Protocol() string { return "xmpp" } @@ -97,7 +97,7 @@ func (xm *XMPP) Configure(c Configuration) error { go xm.connectLoop(xm.connectorLoopNum) for i := 0; i < 42; i++ { - time.Sleep(time.Duration(1)*time.Second) + time.Sleep(time.Duration(1) * time.Second) if xm.connected { return nil } @@ -116,12 +116,12 @@ func (xm *XMPP) connectLoop(num int) { InsecureSkipVerify: true, } options := gxmpp.Options{ - Host: xm.server, - User: xm.jid, - Password: xm.password, - NoTLS: true, - StartTLS: xm.ssl, - Session: true, + Host: xm.server, + User: xm.jid, + Password: xm.password, + NoTLS: true, + StartTLS: xm.ssl, + Session: true, TLSConfig: tc, } var err error @@ -237,8 +237,8 @@ func (xm *XMPP) handleXMPP() error { user := UserID(remote[1] + "@" + remote[0]) event := &Event{ - Type: EVENT_JOIN, - Room: RoomID(remote[0]), + Type: EVENT_JOIN, + Room: RoomID(remote[0]), Author: user, } if v.Type == "unavailable" { @@ -264,8 +264,8 @@ func (xm *XMPP) SetUserInfo(info *UserInfo) error { func (xm *XMPP) SetRoomInfo(roomId RoomID, info *RoomInfo) error { if info.Topic != "" { _, err := xm.conn.Send(gxmpp.Chat{ - Type: "groupchat", - Remote: string(roomId), + Type: "groupchat", + Remote: string(roomId), Subject: info.Topic, }) if err != nil { @@ -324,16 +324,16 @@ func (xm *XMPP) Send(event *Event) error { fmt.Printf("xm *XMPP Send %#v\n", event) if len(event.Recipient) > 0 { _, err := xm.conn.Send(gxmpp.Chat{ - Type: "chat", + Type: "chat", Remote: string(event.Recipient), - Text: event.Text, + Text: event.Text, }) return err } else if len(event.Room) > 0 { _, err := xm.conn.Send(gxmpp.Chat{ - Type: "groupchat", + Type: "groupchat", Remote: string(event.Room), - Text: event.Text, + Text: event.Text, }) return err } else { @@ -346,4 +346,3 @@ func (xm *XMPP) Close() { xm.conn = nil xm.connectorLoopNum += 1 } - diff --git a/main.go b/main.go index 0155892..0864b66 100644 --- a/main.go +++ b/main.go @@ -18,8 +18,8 @@ import ( "git.deuxfleurs.fr/Deuxfleurs/easybridge/appservice" "git.deuxfleurs.fr/Deuxfleurs/easybridge/connector" "git.deuxfleurs.fr/Deuxfleurs/easybridge/connector/irc" - "git.deuxfleurs.fr/Deuxfleurs/easybridge/connector/xmpp" "git.deuxfleurs.fr/Deuxfleurs/easybridge/connector/mattermost" + "git.deuxfleurs.fr/Deuxfleurs/easybridge/connector/xmpp" "git.deuxfleurs.fr/Deuxfleurs/easybridge/mxlib" ) @@ -102,7 +102,7 @@ func readRegistration(file string) mxlib.Registration { AsToken: hex.EncodeToString(rnd[:32]), HsToken: hex.EncodeToString(rnd[32:]), SenderLocalpart: "_ezbr_", - RateLimited: false, + RateLimited: false, Namespaces: mxlib.RegistrationNamespaceSet{ Users: []mxlib.RegistrationNamespace{ mxlib.RegistrationNamespace{ diff --git a/mxlib/client.go b/mxlib/client.go index e07a67a..f8124d3 100644 --- a/mxlib/client.go +++ b/mxlib/client.go @@ -1,12 +1,12 @@ package mxlib import ( - "strings" "bytes" "encoding/json" "fmt" "net/http" "net/url" + "strings" "time" log "github.com/sirupsen/logrus" @@ -280,7 +280,7 @@ func (mx *Client) RoomAvatarAs(room string, pic connector.MediaObject, as_user s "url": mo.MxcUri(), "info": map[string]interface{}{ "mimetype": mo.Mimetype(), - "size": mo.Size(), + "size": mo.Size(), }, } return mx.PutStateAs(room, "m.room.avatar", "", content, as_user) @@ -309,7 +309,7 @@ func (mx *Client) UploadMedia(m connector.MediaObject) (*MediaObject, error) { mx.Server+"/_matrix/media/r0/upload?filename="+url.QueryEscape(m.Filename()), reader) req.Header.Add("Content-Type", m.Mimetype()) - req.ContentLength = m.Size() // TODO: this wasn't specified as mandatory in the matrix client/server spec, do a PR to fix this + req.ContentLength = m.Size() // TODO: this wasn't specified as mandatory in the matrix client/server spec, do a PR to fix this var resp UploadResponse err = mx.DoAndParse(req, &resp) @@ -323,12 +323,12 @@ func (mx *Client) UploadMedia(m connector.MediaObject) (*MediaObject, error) { } media := &MediaObject{ - mxClient: mx, - filename: m.Filename(), - size: m.Size(), - mimetype: m.Mimetype(), - imageSize: m.ImageSize(), - MxcServer: mxc[0], + mxClient: mx, + filename: m.Filename(), + size: m.Size(), + mimetype: m.Mimetype(), + imageSize: m.ImageSize(), + MxcServer: mxc[0], MxcMediaId: mxc[1], } return media, nil @@ -339,16 +339,16 @@ func (mx *Client) ParseMediaInfo(content map[string]interface{}) *MediaObject { info := content["info"].(map[string]interface{}) mxc := strings.Split(strings.Replace(content["url"].(string), "mxc://", "", 1), "/") media := &MediaObject{ - mxClient: mx, - filename: content["body"].(string), - size: int64(info["size"].(float64)), - mimetype: info["mimetype"].(string), - MxcServer: mxc[0], + mxClient: mx, + filename: content["body"].(string), + size: int64(info["size"].(float64)), + mimetype: info["mimetype"].(string), + MxcServer: mxc[0], MxcMediaId: mxc[1], } if content["msgtype"].(string) == "m.image" { media.imageSize = &connector.ImageSize{ - Width: int(info["w"].(float64)), + Width: int(info["w"].(float64)), Height: int(info["h"].(float64)), } } diff --git a/mxlib/mediaobject.go b/mxlib/mediaobject.go index f29127b..a369cfe 100644 --- a/mxlib/mediaobject.go +++ b/mxlib/mediaobject.go @@ -1,21 +1,21 @@ package mxlib import ( - "io" "fmt" - "net/url" + "io" "net/http" + "net/url" "git.deuxfleurs.fr/Deuxfleurs/easybridge/connector" ) type MediaObject struct { - mxClient *Client - filename string - size int64 - mimetype string - imageSize *connector.ImageSize - MxcServer string + mxClient *Client + filename string + size int64 + mimetype string + imageSize *connector.ImageSize + MxcServer string MxcMediaId string } diff --git a/mxlib/registration.go b/mxlib/registration.go index 5aabdd6..e6cce0f 100644 --- a/mxlib/registration.go +++ b/mxlib/registration.go @@ -10,7 +10,7 @@ type Registration struct { AsToken string `yaml:"as_token"` HsToken string `yaml:"hs_token"` SenderLocalpart string `yaml:"sender_localpart"` - RateLimited bool `yaml:"rate_limited"` + RateLimited bool `yaml:"rate_limited"` Namespaces RegistrationNamespaceSet `yaml:"namespaces"` } -- cgit v1.2.3