Skip to content

Commit

Permalink
Remove dependency on spew
Browse files Browse the repository at this point in the history
  • Loading branch information
IngmarStein committed Nov 9, 2024
1 parent fa017d7 commit 94ffa27
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 33 deletions.
5 changes: 1 addition & 4 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ var debug bool
// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "tcp-multiplexer",
Short: "A brief description of your application",
// Uncomment the following line if your bare application
// has an action associated with it:
// Run: func(cmd *cobra.Command, args []string) { },
Short: "Multiplex multiple connections into a single TCP connection.",
}

// Execute adds all child commands to the root command and sets flags appropriately.
Expand Down
3 changes: 1 addition & 2 deletions example/dummy-iso8583-client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"net"
"os"

"github.com/davecgh/go-spew/spew"
"github.com/ingmarstein/tcp-multiplexer/pkg/message"
)

Expand Down Expand Up @@ -38,7 +37,7 @@ func main() {
msg, err := message.ISO8583MessageReader{}.ReadMessage(conn)
handleErr(err)

spew.Dump(msg)
fmt.Printf("%x\n", msg)
}
}

Expand Down
4 changes: 1 addition & 3 deletions example/http-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"net/http"
"net/http/httputil"
"os"

"github.com/davecgh/go-spew/spew"
)

func getPort() string {
Expand All @@ -23,7 +21,7 @@ func headers(w http.ResponseWriter, req *http.Request) {
if err != nil {
fmt.Println(err)
}
spew.Dump(dump)
fmt.Println(dump)

w.Header().Set("Content-Type", "text/html; charset=utf-8")
w.Write([]byte(html.EscapeString(string(dump))))
Expand Down
7 changes: 1 addition & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,9 @@ module github.com/ingmarstein/tcp-multiplexer

go 1.23.2

require (
github.com/davecgh/go-spew v1.1.1
github.com/spf13/cobra v1.8.1
)
require github.com/spf13/cobra v1.8.1

require (
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
8 changes: 0 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
4 changes: 1 addition & 3 deletions pkg/message/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import (
"net/textproto"
"strconv"
"strings"

"github.com/davecgh/go-spew/spew"
)

// https://tools.ietf.org/html/rfc2616
Expand Down Expand Up @@ -110,7 +108,7 @@ func (H HTTPMessageReader) ReadMessage(conn io.Reader) ([]byte, error) {

msg := dumpHTTPMessage(startLine, headers, body)

slog.Debug(spew.Sdump(msg))
slog.Debug(string(msg))

return msg, err
}
Expand Down
6 changes: 2 additions & 4 deletions pkg/message/mpu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"bytes"
"fmt"
"testing"

"github.com/davecgh/go-spew/spew"
)

func TestMPUMessageReader_ReadMessage(t *testing.T) {
Expand All @@ -17,11 +15,11 @@ func TestMPUMessageReader_ReadMessage(t *testing.T) {
buf.WriteByte('a')
}
buf.WriteString("another message")
spew.Dump(buf.Bytes())
fmt.Printf("%x\n", buf)

iso, err := MPUMessageReader{}.ReadMessage(bytes.NewReader(buf.Bytes()))
if err != nil {
t.Fatal("Expected no error, but got:", err)
}
spew.Dump(iso)
fmt.Printf("%x\n", iso)
}
5 changes: 2 additions & 3 deletions pkg/multiplexer/multiplexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"sync"
"time"

"github.com/davecgh/go-spew/spew"
"github.com/ingmarstein/tcp-multiplexer/pkg/message"
)

Expand Down Expand Up @@ -127,7 +126,7 @@ func (mux *Multiplexer) handleConnection(conn net.Conn, sender chan<- *reqContai
break
}

slog.Debug(fmt.Sprintf("Message from client...\n%s", spew.Sdump(msg)))
slog.Debug(fmt.Sprintf("Message from client...\n%x\n", msg))

// enqueue request msg to target conn loop
sender <- &reqContainer{
Expand Down Expand Up @@ -234,7 +233,7 @@ func (mux *Multiplexer) targetConnLoop(requestQueue <-chan *reqContainer) {
err: err,
}

slog.Debug(fmt.Sprintf("Message from target server...\n%s", spew.Sdump(msg)))
slog.Debug(fmt.Sprintf("Message from target server...\n%x\n", msg))

if err != nil {
slog.Error(fmt.Sprintf("target connection: %v", err))
Expand Down

0 comments on commit 94ffa27

Please sign in to comment.