This commit is contained in:
Joel Wetzell
2025-11-18 18:57:39 -06:00
parent e1a8bef3fb
commit b3735ee713
5 changed files with 20 additions and 8 deletions

View File

@@ -29,7 +29,6 @@ func main() {
if err != nil {
return err
}
fmt.Printf("%+v\n", config)
router, err := showbridge.NewRouter(ctx, config)
if err != nil {
return err

View File

@@ -3,6 +3,8 @@ package showbridge
import (
"context"
"fmt"
"log/slog"
"os"
)
type Router struct {
@@ -12,6 +14,14 @@ type Router struct {
func NewRouter(ctx context.Context, config Config) (*Router, error) {
logger := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{
Level: slog.LevelDebug,
}))
slog.SetDefault(logger)
slog.Debug("creating router", "config", config)
router := Router{
Context: ctx,
ModuleInstances: []Module{},

View File

@@ -3,6 +3,7 @@ package showbridge
import (
"context"
"fmt"
"log/slog"
"net"
"time"
)
@@ -49,7 +50,7 @@ func (ts TCPClient) Run(ctx context.Context) error {
for {
client, err := net.Dial("tcp", fmt.Sprintf(":%d", ts.Port))
if err != nil {
fmt.Println(err)
slog.Error(err.Error())
time.Sleep(time.Second * 2)
continue
}
@@ -68,12 +69,12 @@ func (ts TCPClient) Run(ctx context.Context) error {
byteCount, err := client.Read(buffer)
if err != nil {
fmt.Println("connection closed")
slog.Debug("connection closed")
break READ
}
if byteCount > 0 {
fmt.Println(buffer[0:byteCount])
slog.Info(string(buffer[0:byteCount]))
}
}

View File

@@ -3,6 +3,7 @@ package showbridge
import (
"context"
"fmt"
"log/slog"
"net"
)
@@ -31,7 +32,7 @@ func init() {
}
func (ts TCPServer) HandleClient(ctx context.Context, client net.Conn) {
fmt.Printf("handling connection %s\n", client.RemoteAddr())
slog.Info("handling connection", "remoteAddr", client.RemoteAddr().String())
buffer := make([]byte, 1024)
for {
@@ -43,13 +44,13 @@ func (ts TCPServer) HandleClient(ctx context.Context, client net.Conn) {
if err != nil {
if err.Error() == "EOF" {
fmt.Println("connection closed")
slog.Debug("connection closed")
}
return
}
if byteCount > 0 {
fmt.Println(buffer[0:byteCount])
slog.Info(string(buffer[0:byteCount]))
}
}

View File

@@ -4,6 +4,7 @@ import (
"context"
"fmt"
"log"
"log/slog"
"net"
)
@@ -55,7 +56,7 @@ func (us UDPServer) Run(ctx context.Context) error {
if err != nil {
return err
}
fmt.Println(buffer[:numBytes])
slog.Info(string(buffer[:numBytes]))
}
}