Merge pull request #8 from emgee/lint-cleanup
Various lint cleanups. * Simplify if/else * Remove unused and unreachable code * Improve error message format * Fix log message
This commit is contained in:
commit
647313d46c
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
@ -137,7 +136,7 @@ func authenticate(stream *Stream, mechanisms []string, user, password string) er
|
|||
return nil
|
||||
}
|
||||
}
|
||||
return errors.New("No supported SASL mechanism found.")
|
||||
return errors.New("no supported SASL mechanism found")
|
||||
}
|
||||
|
||||
type authHandler struct {
|
||||
|
|
@ -158,9 +157,11 @@ 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 {
|
||||
|
|
@ -176,8 +177,6 @@ func authenticateResponse(stream *Stream) error {
|
|||
default:
|
||||
return fmt.Errorf("Unexpected: %s", se.Name)
|
||||
}
|
||||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
|
||||
type saslAuth struct {
|
||||
|
|
|
|||
|
|
@ -35,9 +35,10 @@ 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)
|
||||
}
|
||||
|
|
@ -48,8 +49,6 @@ func startComponent(stream *Stream, jid JID) (string, error) {
|
|||
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 {
|
||||
start, err := stream.Next()
|
||||
if err != nil {
|
||||
return err
|
||||
} else {
|
||||
}
|
||||
if start.Name != (xml.Name{nsComponentAccept, "handshake"}) {
|
||||
return fmt.Errorf("Expected <handshake/>, for %s", start.Name)
|
||||
}
|
||||
}
|
||||
if err := stream.Skip(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return stream.Skip()
|
||||
}
|
||||
|
||||
type saslHandshake struct {
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ type Stream struct {
|
|||
incomingNamespace nsMap
|
||||
}
|
||||
|
||||
// Create a XML stream connection. A Steam is used by an XMPP instance to
|
||||
// Create a XML stream connection. A Stream is used by an XMPP instance to
|
||||
// handle sending and receiving XML data over the net connection.
|
||||
func NewStream(addr string, config *StreamConfig) (*Stream, error) {
|
||||
|
||||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -76,8 +76,8 @@ func (fn MatcherFunc) Match(v interface{}) bool {
|
|||
return fn(v)
|
||||
}
|
||||
|
||||
// Uniquly identifies a stream fiter. Used to remove a filter that's no longer
|
||||
// needed.
|
||||
// Uniquely identifies a stream filter. Used to remove a filter that's no
|
||||
// longer needed.
|
||||
type FilterId int64
|
||||
|
||||
// Implements the error interface for a FilterId.
|
||||
|
|
|
|||
Loading…
Reference in New Issue