diff options
author | xengineering <me@xengineering.eu> | 2023-06-27 15:51:09 +0200 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2023-06-27 15:51:09 +0200 |
commit | 8965adcdbc5ccf30afdccac31cc3a6f9d7451b91 (patch) | |
tree | 1a33b14bf505ebca382afd5dfa789f5e8117b285 | |
parent | d27744d56b41aa9dd68502bd529dbf3fc083ed1d (diff) | |
download | limox-8965adcdbc5ccf30afdccac31cc3a6f9d7451b91.tar limox-8965adcdbc5ccf30afdccac31cc3a6f9d7451b91.tar.zst limox-8965adcdbc5ccf30afdccac31cc3a6f9d7451b91.zip |
Apply go fmt
-rw-r--r-- | limox.go | 6 | ||||
-rw-r--r-- | xmpp/encoder_decoder.go | 52 | ||||
-rw-r--r-- | xmpp/jid_test.go | 22 | ||||
-rw-r--r-- | xmpp/session.go | 12 |
4 files changed, 57 insertions, 35 deletions
@@ -26,8 +26,8 @@ type Limox struct { JidEditor widget.Editor PwdEditor widget.Editor MainButton widget.Clickable - sessionIn chan any - sessionOut chan any + sessionIn chan any + sessionOut chan any State LimoxState Window *app.Window Operations op.Ops @@ -42,7 +42,7 @@ func NewLimox() Limox { ), Operations: op.Ops{}, Theme: material.NewTheme(gofont.Collection()), - sessionOut: make(chan any), + sessionOut: make(chan any), State: Disconnected, } diff --git a/xmpp/encoder_decoder.go b/xmpp/encoder_decoder.go index 7a917da..c340b09 100644 --- a/xmpp/encoder_decoder.go +++ b/xmpp/encoder_decoder.go @@ -2,18 +2,18 @@ package xmpp import ( "encoding/xml" - "log" + "errors" "io" + "log" "os" - "errors" ) -type encoderDecoder struct{ - session *session - ct *xml.Encoder // client transport encoder - cl *xml.Encoder // client log encoder - st *xml.Decoder // server transport decoder - sl *xml.Encoder // server log encoder +type encoderDecoder struct { + session *session + ct *xml.Encoder // client transport encoder + cl *xml.Encoder // client log encoder + st *xml.Decoder // server transport decoder + sl *xml.Encoder // server log encoder terminator chan bool } @@ -38,17 +38,29 @@ func newEncoderDecoder(s *session) encoderDecoder { func (ed *encoderDecoder) encodeToken(t xml.Token) error { var err error - defer func() { if err != nil { log.Println(err) } }() + defer func() { + if err != nil { + log.Println(err) + } + }() err = ed.ct.EncodeToken(t) - if err != nil { return err } + if err != nil { + return err + } err = ed.ct.Flush() - if err != nil { return err } + if err != nil { + return err + } err = ed.cl.EncodeToken(t) - if err != nil { return err } + if err != nil { + return err + } err = ed.cl.Flush() - if err != nil { return err } + if err != nil { + return err + } return nil } @@ -62,15 +74,21 @@ func (ed *encoderDecoder) run() { t, err := ed.st.Token() if t != nil && err == nil { err = ed.sl.EncodeToken(t) - if err != nil { log.Println("Could not encode to server stream log") } + if err != nil { + log.Println("Could not encode to server stream log") + } err = ed.sl.Flush() - if err != nil { log.Println("Could not flush server stream log") } + if err != nil { + log.Println("Could not flush server stream log") + } c := xml.CopyToken(t) ed.session.rx <- c } if err != nil { - if errors.Is(err, io.EOF) { return } - log.Println(err) // FIXME terminate session on error + if errors.Is(err, io.EOF) { + return + } + log.Println(err) // FIXME terminate session on error return } } diff --git a/xmpp/jid_test.go b/xmpp/jid_test.go index 6f8b9fd..7b6874a 100644 --- a/xmpp/jid_test.go +++ b/xmpp/jid_test.go @@ -7,13 +7,13 @@ import ( func TestDomainpart(t *testing.T) { var data = map[string]string{ "user@example.org/ressource": "example.org", - "example.org/ressource": "example.org", - "user@example.org": "example.org", - "example.org": "example.org", - "test.eu": "test.eu", + "example.org/ressource": "example.org", + "user@example.org": "example.org", + "example.org": "example.org", + "test.eu": "test.eu", } - for k, v := range(data) { + for k, v := range data { if domainpart(k) != v { t.Fatalf("Domain part of JID '%s' is not '%s'!", k, v) } @@ -23,14 +23,14 @@ func TestDomainpart(t *testing.T) { func TestUsername(t *testing.T) { var data = map[string]string{ "user@example.org/ressource": "user", - "example.org/ressource": "", - "user@example.org": "user", - "df%§df?LÖ@example.org": "df%§df?LÖ", - "example.org": "", - "test.eu": "", + "example.org/ressource": "", + "user@example.org": "user", + "df%§df?LÖ@example.org": "df%§df?LÖ", + "example.org": "", + "test.eu": "", } - for k, v := range(data) { + for k, v := range data { if username(k) != v { t.Fatalf("Username of JID '%s' is not '%s'!", k, v) } diff --git a/xmpp/session.go b/xmpp/session.go index e928f01..9959c80 100644 --- a/xmpp/session.go +++ b/xmpp/session.go @@ -3,8 +3,8 @@ package xmpp import ( "crypto/tls" "crypto/x509" - "log" "encoding/xml" + "log" ) type SessionConnect struct{} @@ -37,7 +37,9 @@ func (s *session) run() { defer func() { s.out <- SessionDisconnect{} }() err := s.startTransport() - if err != nil { return } + if err != nil { + return + } defer s.transport.Close() s.ed = newEncoderDecoder(s) @@ -53,8 +55,10 @@ func (s *session) run() { select { case data := <-s.in: switch data.(type) { - case SessionShouldDisconnect: return - default: log.Printf("Unknown data '%d'!\n", data) + case SessionShouldDisconnect: + return + default: + log.Printf("Unknown data '%d'!\n", data) } case _ = <-s.rx: // TODO route received XML token here |