Add basic IRC listener

This commit is contained in:
Simon Ser 2020-02-04 10:46:22 +01:00
commit 8e31fde0ab
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48
5 changed files with 66 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/jounce

20
cmd/jounce/main.go Normal file
View File

@ -0,0 +1,20 @@
package main
import (
"log"
"net"
"git.sr.ht/~emersion/jounce"
)
func main() {
addr := ":6667"
ln, err := net.Listen("tcp", addr)
if err != nil {
log.Fatalf("failed to start listener: %v", err)
}
log.Printf("Server listening on %v", addr)
log.Fatal(jounce.Serve(ln))
}

5
go.mod Normal file
View File

@ -0,0 +1,5 @@
module git.sr.ht/~emersion/jounce
go 1.13
require gopkg.in/irc.v3 v3.1.0

2
go.sum Normal file
View File

@ -0,0 +1,2 @@
gopkg.in/irc.v3 v3.1.0 h1:AeDaEhQ/78gHfpbj/3mSi8FfiNIsFiVrWEgLzOwHWnU=
gopkg.in/irc.v3 v3.1.0/go.mod h1:qE0DWv0j8Z8wCbFhA9783JBO0bufi3rttcV1Sjin8io=

38
server.go Normal file
View File

@ -0,0 +1,38 @@
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)
}
}()
}
}