Add basic IRC listener
This commit is contained in:
commit
8e31fde0ab
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/jounce
|
20
cmd/jounce/main.go
Normal file
20
cmd/jounce/main.go
Normal 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
5
go.mod
Normal 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
2
go.sum
Normal 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
38
server.go
Normal 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)
|
||||
}
|
||||
}()
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user