1
0
Fork 0
forked from External/ergo

massive refactor and basic channel support: join, part, message

This commit is contained in:
Jeremy Latt 2012-12-08 22:54:58 -08:00
parent 8ac1909c19
commit 24ad2172a8
10 changed files with 657 additions and 191 deletions

View file

@ -3,8 +3,8 @@ package irc
import (
"bufio"
"log"
"strings"
"net"
"strings"
)
func readTrimmedLine(reader *bufio.Reader) (string, error) {
@ -20,7 +20,7 @@ func StringReadChan(conn net.Conn) <-chan string {
go func() {
for {
line, err := readTrimmedLine(reader)
if (line != "") {
if line != "" {
ch <- line
log.Printf("%s -> %s", addr, line)
}
@ -50,3 +50,16 @@ func StringWriteChan(conn net.Conn) chan<- string {
return ch
}
func LookupHostname(addr net.Addr) string {
addrStr := addr.String()
ipaddr, _, err := net.SplitHostPort(addrStr)
if err != nil {
return addrStr
}
names, err := net.LookupAddr(ipaddr)
if err != nil {
return ipaddr
}
return names[0]
}