From 9320db21fd036baacf722c7dcf529a3a500ff963 Mon Sep 17 00:00:00 2001 From: IngCr3at1on Date: Wed, 30 Oct 2019 17:53:31 -0500 Subject: [PATCH] Remove test client and update api slightly to allow for the CLI client to connect. --- internal/api.go | 9 ++--- test_client/main.go | 88 --------------------------------------------- 2 files changed, 5 insertions(+), 92 deletions(-) delete mode 100644 test_client/main.go diff --git a/internal/api.go b/internal/api.go index d3ddf58..6bb06b9 100644 --- a/internal/api.go +++ b/internal/api.go @@ -16,7 +16,7 @@ import ( "github.com/gorilla/websocket" "github.com/justanotherorganization/l5424" "github.com/justanotherorganization/l5424/x5424" - "github.com/labstack/echo" + "github.com/labstack/echo/v4" "github.com/pkg/errors" ) @@ -65,9 +65,10 @@ func makeConnectHandler(cfg *config.Config) echo.HandlerFunc { for { out := <-outCh if out != nil { - // FIXME: I really don't like this way of breaking out ANSI instructions - // into something to pass over the websocket... - out.Data = ansi.ReplaceCodes(out.Data) + if p := c.QueryParam("replace"); p == "true" || p == `` { + out.Data = ansi.ReplaceCodes(out.Data) + } + if strings.HasPrefix(out.Data, ansi.Instruction) { out.Type = pb.Output_INSTRUCTION fields := strings.Split(out.Data, ansi.Separator) diff --git a/test_client/main.go b/test_client/main.go deleted file mode 100644 index 1e6ef2a..0000000 --- a/test_client/main.go +++ /dev/null @@ -1,88 +0,0 @@ -package main - -import ( - "bufio" - "context" - "fmt" - "io" - "net/url" - "os" - "os/signal" - "syscall" - - "github.com/gorilla/websocket" -) - -var usage = "Usage: %s \n" - -func _main() error { - sc := make(chan os.Signal, 1) - signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill) - - ctx, cancel := context.WithCancel(context.Background()) - go func() { - <-sc - cancel() - }() - - var args []string - if args = os.Args[1:]; len(args) != 1 { - return fmt.Errorf(usage, os.Args[0]) - } - - _url := url.URL{Scheme: "ws", Host: args[0], Path: "/api/connect"} - fmt.Println("dialing " + _url.String()) - conn, _, err := websocket.DefaultDialer.Dial(_url.String(), nil) - if err != nil { - return err - } - defer conn.Close() - - errCh := make(chan error, 1) - go func() { - scanner := bufio.NewScanner(os.Stdin) - for scanner.Scan() { - err = conn.WriteMessage(websocket.TextMessage, scanner.Bytes()) - if err != nil { - errCh <- err - return - } - } - - if err := scanner.Err(); err != nil { - if err != io.EOF { - errCh <- err - } - } - }() - - go func() { - for { - _, byt, err := conn.ReadMessage() - if err != nil { - errCh <- err - return - } - - fmt.Print(string(byt)) - } - }() - - select { - case <-ctx.Done(): - break - case err := <-errCh: - if err != nil { - return err - } - } - - return nil -} - -func main() { - if err := _main(); err != nil { - fmt.Fprintln(os.Stderr, err.Error()) - os.Exit(1) - } -}