diff --git a/src/xmpp/client.go b/src/xmpp/client.go
index a53d920..293d67e 100644
--- a/src/xmpp/client.go
+++ b/src/xmpp/client.go
@@ -93,14 +93,13 @@ func startClient(stream *Stream, jid JID) error {
},
}
- if rstart, err := stream.SendStart(&start); err != nil {
+ rstart, err := stream.SendStart(&start)
+ if err != nil {
return err
- } else {
- if rstart.Name != (xml.Name{nsStreams, "stream"}) {
- return fmt.Errorf("unexpected start element: %s", rstart.Name)
- }
}
-
+ if rstart.Name != (xml.Name{nsStreams, "stream"}) {
+ return fmt.Errorf("unexpected start element: %s", rstart.Name)
+ }
return nil
}
@@ -158,26 +157,26 @@ func authenticatePlain(stream *Stream, user, password string) error {
}
func authenticateResponse(stream *Stream) error {
- if se, err := stream.Next(); err != nil {
+ se, err := stream.Next()
+ if err != nil {
return err
- } else {
- switch se.Name.Local {
- case "success":
- if err := stream.Skip(); err != nil {
- return err
- }
- return nil
- case "failure":
- f := new(saslFailure)
- if err := stream.Decode(f, se); err != nil {
- return err
- }
- return fmt.Errorf("Authentication failed: %s", f.Reason.Local)
- default:
- return fmt.Errorf("Unexpected: %s", se.Name)
- }
}
- panic("unreachable")
+
+ switch se.Name.Local {
+ case "success":
+ if err := stream.Skip(); err != nil {
+ return err
+ }
+ return nil
+ case "failure":
+ f := new(saslFailure)
+ if err := stream.Decode(f, se); err != nil {
+ return err
+ }
+ return fmt.Errorf("Authentication failed: %s", f.Reason.Local)
+ default:
+ return fmt.Errorf("Unexpected: %s", se.Name)
+ }
}
type saslAuth struct {
diff --git a/src/xmpp/component.go b/src/xmpp/component.go
index 84cd628..0ae3706 100644
--- a/src/xmpp/component.go
+++ b/src/xmpp/component.go
@@ -35,21 +35,20 @@ func startComponent(stream *Stream, jid JID) (string, error) {
var streamId string
- if rstart, err := stream.SendStart(&start); err != nil {
+ rstart, err := stream.SendStart(&start)
+ if err != nil {
return "", err
- } else {
- if rstart.Name != (xml.Name{nsStreams, "stream"}) {
- return "", fmt.Errorf("unexpected start element: %s", rstart.Name)
- }
- // Find the stream id.
- for _, attr := range rstart.Attr {
- if attr.Name.Local == "id" {
- streamId = attr.Value
- break
- }
+ }
+ if rstart.Name != (xml.Name{nsStreams, "stream"}) {
+ return "", fmt.Errorf("unexpected start element: %s", rstart.Name)
+ }
+ // Find the stream id.
+ for _, attr := range rstart.Attr {
+ if attr.Name.Local == "id" {
+ streamId = attr.Value
+ break
}
}
-
if streamId == "" {
return "", errors.New("Missing stream id")
}
@@ -70,18 +69,14 @@ func handshake(stream *Stream, streamId, secret string) error {
}
// Get handshake response.
- if start, err := stream.Next(); err != nil {
- return err
- } else {
- if start.Name != (xml.Name{nsComponentAccept, "handshake"}) {
- return fmt.Errorf("Expected , for %s", start.Name)
- }
- }
- if err := stream.Skip(); err != nil {
+ start, err := stream.Next()
+ if err != nil {
return err
}
-
- return nil
+ if start.Name != (xml.Name{nsComponentAccept, "handshake"}) {
+ return fmt.Errorf("Expected , for %s", start.Name)
+ }
+ return stream.Skip()
}
type saslHandshake struct {
diff --git a/src/xmpp/stanza.go b/src/xmpp/stanza.go
index 4d48bf1..37ec80d 100644
--- a/src/xmpp/stanza.go
+++ b/src/xmpp/stanza.go
@@ -115,12 +115,11 @@ type Error struct {
}
func (e Error) Error() string {
- if text := e.Text(); text == "" {
+ text := e.Text()
+ if text == "" {
return fmt.Sprintf("[%s] %s", e.Type, e.Condition().Local)
- } else {
- return fmt.Sprintf("[%s] %s, %s", e.Type, e.Condition().Local, text)
}
- panic("unreachable")
+ return fmt.Sprintf("[%s] %s, %s", e.Type, e.Condition().Local, text)
}
type errorText struct {
diff --git a/src/xmpp/stream.go b/src/xmpp/stream.go
index d2dc777..0b3d9c1 100644
--- a/src/xmpp/stream.go
+++ b/src/xmpp/stream.go
@@ -148,11 +148,11 @@ func (stream *Stream) Next() (*xml.StartElement, error) {
}
if stream.config.LogStanzas {
- if xml, err := collectElement(stream.dec, start, stream.incomingNamespace); err != nil {
+ xml, err := collectElement(stream.dec, start, stream.incomingNamespace)
+ if err != nil {
return nil, err
- } else {
- stream.stanzaBuf = xml
}
+ stream.stanzaBuf = xml
log.Println("recv:", stream.stanzaBuf)
}
@@ -170,7 +170,7 @@ func nextStartElement(dec *xml.Decoder) (*xml.StartElement, error) {
}
switch e := t.(type) {
case xml.StartElement:
- for i, _ := range e.Attr {
+ for i := range e.Attr {
// Replace URL namespace to xml in order to avoid error on Unmarshal
// It's quite ugly, but working for now
if e.Attr[i].Name.Space == "http://www.w3.org/XML/1998/namespace" {
@@ -183,7 +183,6 @@ func nextStartElement(dec *xml.Decoder) (*xml.StartElement, error) {
return nil, io.EOF
}
}
- panic("Unreachable")
}
// Skip reads tokens until it reaches the end element of the most recent start
@@ -205,11 +204,11 @@ func (stream *Stream) Decode(v interface{}, start *xml.StartElement) error {
// Explicity lookup next start element to ensure stream is validated,
// stanza is logged, etc.
if start == nil {
- if se, err := stream.Next(); err != nil {
+ se, err := stream.Next()
+ if err != nil {
return err
- } else {
- start = se
}
+ start = se
}
if stream.config.LogStanzas {
diff --git a/src/xmpp/xml.go b/src/xmpp/xml.go
index 76993ef..6f65dd3 100644
--- a/src/xmpp/xml.go
+++ b/src/xmpp/xml.go
@@ -76,14 +76,13 @@ func writeXMLAttr(w io.Writer, attr xml.Attr) error {
func startElementIter(dec *xml.Decoder) func() *xml.StartElement {
return func() *xml.StartElement {
for {
- if tok, err := dec.Token(); err != nil {
+ tok, err := dec.Token()
+ if err != nil {
return nil
- } else {
- if start, ok := tok.(xml.StartElement); ok {
- return &start
- }
+ }
+ if start, ok := tok.(xml.StartElement); ok {
+ return &start
}
}
- return nil
}
}