package main import ( "context" "fmt" "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/logger" "code.ndumas.com/ndumas/gomud/telnet" ) var ( port int ) func main() { l, err := net.Listen("tcp", fmt.Sprintf(":%d", port)) if err != nil { log.Fatalf("error binding to port %d\n: %s", port, err) } defer l.Close() wmLogger := watermill.NewStdLogger(false, false) wrappedSlogger := logger.NewWrappedSlogger() router, err := message.NewRouter(message.RouterConfig{}, wrappedSlogger) 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, wrappedSlogger) tp := telnet.NewTELNETParser(ctx, pubSub, wrappedSlogger) go tp.Handle() for { conn, err := ts.l.Accept() if err != nil { log.Fatal(err) } go ts.Handle(conn) } }