diff --git a/cmd/echo/main.go b/cmd/echo/main.go new file mode 100644 index 0000000..d453196 --- /dev/null +++ b/cmd/echo/main.go @@ -0,0 +1,50 @@ +package main + +import ( + "context" + "log" + "net" + + "github.com/ThreeDotsLabs/watermill" + "github.com/ThreeDotsLabs/watermill/message" + "github.com/ThreeDotsLabs/watermill/message/router/middleware" + "github.com/ThreeDotsLabs/watermill/message/router/plugin" + "github.com/ThreeDotsLabs/watermill/pubsub/gochannel" + + "code.ndumas.com/ndumas/gomud/telnet" +) + +func main() { + l, err := net.Listen("tcp", ":5555") + if err != nil { + log.Fatal(err) + } + defer l.Close() + wmLogger := watermill.NewStdLogger(false, false) + + logger := NewWrappedSlogger() + router, err := message.NewRouter(message.RouterConfig{}, logger) + + router.AddPlugin(plugin.SignalsHandler) + + router.AddMiddleware( + middleware.CorrelationID, + middleware.Recoverer, + ) + + pubSub := gochannel.NewGoChannel(gochannel.Config{}, wmLogger) + + ctx := context.Background() + ts := telnet.NewTELNETServer(ctx, l, pubSub, logger) + tp := telnet.NewTELNETParser(ctx, pubSub, logger) + go tp.Handle() + + for { + conn, err := ts.l.Accept() + if err != nil { + log.Fatal(err) + } + + go ts.Handle(conn) + } +} diff --git a/cmd/echo/server.go b/cmd/echo/server.go index ed6b0fc..06ab7d0 100644 --- a/cmd/echo/server.go +++ b/cmd/echo/server.go @@ -1,48 +1 @@ package main - -import ( - "context" - "log" - "net" - - "github.com/ThreeDotsLabs/watermill" - "github.com/ThreeDotsLabs/watermill/message" - "github.com/ThreeDotsLabs/watermill/message/router/middleware" - "github.com/ThreeDotsLabs/watermill/message/router/plugin" - "github.com/ThreeDotsLabs/watermill/pubsub/gochannel" -) - -func main() { - l, err := net.Listen("tcp", ":5555") - if err != nil { - log.Fatal(err) - } - defer l.Close() - wmLogger := watermill.NewStdLogger(false, false) - - logger := NewWrappedSlogger() - router, err := message.NewRouter(message.RouterConfig{}, logger) - - router.AddPlugin(plugin.SignalsHandler) - - router.AddMiddleware( - middleware.CorrelationID, - middleware.Recoverer, - ) - - pubSub := gochannel.NewGoChannel(gochannel.Config{}, wmLogger) - - ctx := context.Background() - ts := NewTELNETServer(ctx, l, pubSub, logger) - tp := NewTELNETParser(ctx, pubSub, logger) - go tp.Handle() - - for { - conn, err := ts.l.Accept() - if err != nil { - log.Fatal(err) - } - - go ts.Handle(conn) - } -} diff --git a/protocol/telnet.go b/protocol/telnet.go deleted file mode 100644 index 2d0eaff..0000000 --- a/protocol/telnet.go +++ /dev/null @@ -1 +0,0 @@ -package protocol diff --git a/protocol/BUILD.bazel b/telnet/BUILD.bazel similarity index 100% rename from protocol/BUILD.bazel rename to telnet/BUILD.bazel diff --git a/cmd/echo/telnet.go b/telnet/telnet.go similarity index 82% rename from cmd/echo/telnet.go rename to telnet/telnet.go index 05432ea..942a3df 100644 --- a/cmd/echo/telnet.go +++ b/telnet/telnet.go @@ -1,4 +1,4 @@ -package main +package telnet import ( "bufio" @@ -11,10 +11,17 @@ import ( "github.com/ThreeDotsLabs/watermill/message/router/middleware" ) +type TELNETOption struct { + Us, UsQ, Them, ThemQ bool +} + +type TELNETOptions map[string]TELNETOption + type TELNETParser struct { s message.Subscriber c context.Context logger watermill.LoggerAdapter + to TELNETOptions } func (tp *TELNETParser) Handle() { @@ -27,7 +34,7 @@ func (tp *TELNETParser) Handle() { fields := make(watermill.LogFields) fields["body"] = string(message.Payload) fields["correlation_id"] = string(message.Metadata["correlation_id"]) - tp.logger.Info("received raw TCP line", fields) + tp.logger.Trace("received raw TCP line", fields) message.Ack() } @@ -46,6 +53,7 @@ type TELNETServer struct { p message.Publisher c context.Context logger watermill.LoggerAdapter + to TELNETOptions } func NewTELNETServer(c context.Context, l net.Listener, p message.Publisher, wml watermill.LoggerAdapter) *TELNETServer { @@ -62,6 +70,8 @@ func NewTELNETServer(c context.Context, l net.Listener, p message.Publisher, wml func (ts *TELNETServer) Handle(conn net.Conn) { s := bufio.NewScanner(conn) defer conn.Close() + // i need to create an ecs Renderer that targets a iw.Writer (net.Conn) + // the renderer correlationID := watermill.NewUUID() ts.logger = ts.logger.With( @@ -77,6 +87,6 @@ func (ts *TELNETServer) Handle(conn net.Conn) { if err != nil { log.Fatalln("couldn't write to telnet.raw") } - ts.logger.Info("received bytes over telnet", nil) + ts.logger.Trace("received bytes over telnet", nil) } }