more refactoring
parent
3566309c3d
commit
71ee479873
@ -0,0 +1,44 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"context"
|
||||
"log"
|
||||
"net"
|
||||
|
||||
"github.com/ThreeDotsLabs/watermill"
|
||||
"github.com/ThreeDotsLabs/watermill/message"
|
||||
)
|
||||
|
||||
type TELNETParser struct {
|
||||
}
|
||||
|
||||
type TELNETServer struct {
|
||||
l net.Listener
|
||||
p message.Publisher
|
||||
c context.Context
|
||||
}
|
||||
|
||||
func NewTELNETServer(c context.Context, l net.Listener, p message.Publisher) *TELNETServer {
|
||||
ts := TELNETServer{
|
||||
c: c,
|
||||
l: l,
|
||||
p: p,
|
||||
}
|
||||
|
||||
return &ts
|
||||
}
|
||||
|
||||
func (ts *TELNETServer) Handle(conn net.Conn) {
|
||||
s := bufio.NewScanner(conn)
|
||||
defer conn.Close()
|
||||
|
||||
for s.Scan() {
|
||||
t := s.Text()
|
||||
err := ts.p.Publish("telnet.raw", message.NewMessage(watermill.NewUUID(), []byte(t)))
|
||||
if err != nil {
|
||||
log.Fatalln("couldn't write to raw_telnet queue")
|
||||
}
|
||||
log.Printf("Received user input: %q\n", t)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue