soju/server.go

39 lines
545 B
Go
Raw Normal View History

2020-02-04 09:46:22 +00:00
package jounce
import (
"fmt"
"log"
"net"
"gopkg.in/irc.v3"
)
func handleConn(conn net.Conn) error {
defer conn.Close()
ircConn := irc.NewConn(conn)
for {
msg, err := ircConn.ReadMessage()
if err != nil {
return err
}
log.Println(msg)
}
}
func Serve(ln net.Listener) error {
for {
conn, err := ln.Accept()
if err != nil {
return fmt.Errorf("failed to accept connection: %v", err)
}
go func() {
if err := handleConn(conn); err != nil {
log.Printf("error handling connection: %v", err)
}
}()
}
}