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

Logging #13

Merged
merged 1 commit into from
Dec 15, 2023
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
18 changes: 18 additions & 0 deletions cmd/client/main.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package main

import (
"fmt"
"io"
"net"
"os"

"github.com/spf13/cobra"
"github.com/yezzey-gp/yproxy/config"
"github.com/yezzey-gp/yproxy/pkg/client"
"github.com/yezzey-gp/yproxy/pkg/proc"
"github.com/yezzey-gp/yproxy/pkg/ylogger"
)
Expand Down Expand Up @@ -75,6 +77,9 @@ var putCmd = &cobra.Command{
return err
}

ycl := client.NewYClient(con)
r := proc.NewProtoReader(ycl)

defer con.Close()
msg := proc.NewPutMessage(args[0], encrypt).Encode()
_, err = con.Write(msg)
Expand Down Expand Up @@ -120,6 +125,19 @@ var putCmd = &cobra.Command{
return err
}

tp, _, err := r.ReadPacket()
if err != nil {
return err
}

if tp == proc.MessageTypeReadyForQuery {
// ok

ylogger.Zero.Debug().Msg("got rfq")
} else {
return fmt.Errorf("failed to get rfq")
}

return nil
},
}
Expand Down
10 changes: 10 additions & 0 deletions pkg/proc/interaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ func ProcConn(s storage.StorageInteractor, cr crypt.Crypter, ycl *client.YClient
}
io.Copy(ycl.Conn, r)

_ = ycl.Conn.Close()

case MessageTypePut:

msg := PutMessage{}
Expand Down Expand Up @@ -106,6 +108,14 @@ func ProcConn(s storage.StorageInteractor, cr crypt.Crypter, ycl *client.YClient
return ycl.Conn.Close()
}

_, err = ycl.Conn.Write(NewReadyForQueryMessage().Encode())

if err != nil {
_ = ycl.ReplyError(err, "failed to upload")

return ycl.Conn.Close()
}

default:

_ = ycl.ReplyError(nil, "wrong request type")
Expand Down