Implement Stringer on connection

This commit is contained in:
Matt Joiner 2015-06-29 19:37:52 +10:00
parent c41aa941f3
commit 58dd6ddf93
1 changed files with 7 additions and 0 deletions

View File

@ -2,6 +2,7 @@ package torrent
import ( import (
"bufio" "bufio"
"bytes"
"container/list" "container/list"
"encoding" "encoding"
"errors" "errors"
@ -234,6 +235,12 @@ func (cn *connection) statusFlags() (ret string) {
return return
} }
func (cn *connection) String() string {
var buf bytes.Buffer
cn.WriteStatus(&buf, nil)
return buf.String()
}
func (cn *connection) WriteStatus(w io.Writer, t *torrent) { func (cn *connection) WriteStatus(w io.Writer, t *torrent) {
// \t isn't preserved in <pre> blocks? // \t isn't preserved in <pre> blocks?
fmt.Fprintf(w, "%+q: %s-%s\n", cn.PeerID, cn.localAddr(), cn.remoteAddr()) fmt.Fprintf(w, "%+q: %s-%s\n", cn.PeerID, cn.localAddr(), cn.remoteAddr())