Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make read/write debug messages a bit easier to read #71

Merged
merged 1 commit into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion command.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (srv *Server) consumeCommands(ctx context.Context, conn net.Conn, reader *b
// NOTE: we increase the wait group by one in order to make sure that idle
// connections are not blocking a close.
srv.wg.Add(1)
srv.logger.Debug("incoming command", slog.Int("length", length), slog.String("type", string(t)))
srv.logger.Debug("<- incoming command", slog.Int("length", length), slog.String("type", t.String()))
err = srv.handleCommand(ctx, conn, t, reader, writer)
srv.wg.Done()
if errors.Is(err, io.EOF) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/buffer/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (writer *Writer) End() error {
binary.BigEndian.PutUint32(bytes[1:5], length)
_, err := writer.Writer.Write(bytes)

writer.logger.Debug("writing message", slog.String("type", string(bytes[0])))
writer.logger.Debug("-> writing message", slog.String("type", types.ServerMessage(bytes[0]).String()))
return err
}

Expand Down
72 changes: 72 additions & 0 deletions pkg/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,75 @@ const (
ServerReady ServerMessage = 'Z'
ServerRowDescription ServerMessage = 'T'
)

func (m ClientMessage) String() string {
switch m {
case ClientBind:
return "Bind"
case ClientClose:
return "Close"
case ClientCopyData:
return "CopyData"
case ClientCopyDone:
return "CopyDone"
case ClientCopyFail:
return "CopyFail"
case ClientDescribe:
return "Describe"
case ClientExecute:
return "Execute"
case ClientFlush:
return "Flush"
case ClientParse:
return "Parse"
case ClientPassword:
return "Password"
case ClientSimpleQuery:
return "SimpleQuery"
case ClientSync:
return "Sync"
case ClientTerminate:
return "Terminate"
default:
return "Unknown"
}
}

func (m ServerMessage) String() string {
switch m {
case ServerAuth:
return "Auth"
case ServerBindComplete:
return "BindComplete"
case ServerCommandComplete:
return "CommandComplete"
case ServerCloseComplete:
return "CloseComplete"
case ServerCopyInResponse:
return "CopyInResponse"
case ServerDataRow:
return "DataRow"
case ServerEmptyQuery:
return "EmptyQuery"
case ServerErrorResponse:
return "ErrorResponse"
case ServerNoticeResponse:
return "NoticeResponse"
case ServerNoData:
return "NoData"
case ServerParameterDescription:
return "ParameterDescription"
case ServerParameterStatus:
return "ParameterStatus"
case ServerParseComplete:
return "ParseComplete"
case ServerPortalSuspended:
return "PortalSuspended"
case ServerReady:
return "Ready"
case ServerRowDescription:
return "RowDescription"
default:
return "Unknown"
}
}
Loading