From 4ebcb18fde67c2ae6ac1a0c28906388eb4846136 Mon Sep 17 00:00:00 2001 From: AndrewLondon Date: Tue, 12 Mar 2024 16:24:08 +0000 Subject: [PATCH] CHat server Updated --- go.mod | 7 ++++- go.sum | 23 +++++++++++++++ grpc/cmd/grpc_server/main.go | 6 ++-- internal/api/chat_v1/chat_api.proto | 46 +++++++++++++++++++++++++++++ internal/config/config.go | 14 +++++++++ 5 files changed, 93 insertions(+), 3 deletions(-) create mode 100644 internal/api/chat_v1/chat_api.proto create mode 100644 internal/config/config.go diff --git a/go.mod b/go.mod index 3e593c4..f05de7b 100644 --- a/go.mod +++ b/go.mod @@ -4,14 +4,19 @@ go 1.20 require ( github.com/fatih/color v1.16.0 - github.com/golang/protobuf v1.5.3 + github.com/jackc/pgx/v5 v5.5.5 + github.com/joho/godotenv v1.5.1 google.golang.org/grpc v1.61.1 google.golang.org/protobuf v1.32.0 ) require ( + github.com/golang/protobuf v1.5.3 // indirect + github.com/jackc/pgpassfile v1.0.0 // indirect + github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect + golang.org/x/crypto v0.17.0 // indirect golang.org/x/net v0.18.0 // indirect golang.org/x/sys v0.15.0 // indirect golang.org/x/text v0.14.0 // indirect diff --git a/go.sum b/go.sum index 20a5e57..1a58027 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,5 @@ +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM= github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= @@ -5,13 +7,31 @@ github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= +github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg= +github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk= +github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= +github.com/jackc/pgx/v5 v5.5.5 h1:amBjrZVmksIdNjxGW/IiIMzxMKZFelXbUoPNb+8sjQw= +github.com/jackc/pgx/v5 v5.5.5/go.mod h1:ez9gk+OAat140fv9ErkZDYFWmXLfV+++K0uAOiwgm1A= +github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk= +github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= +github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +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/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= +golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k= +golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= golang.org/x/net v0.18.0 h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg= golang.org/x/net v0.18.0/go.mod h1:/czyP5RqHAH4odGYxBJ1qz0+CE5WZ+2j1YgoEo8F2jQ= +golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= @@ -27,3 +47,6 @@ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp0 google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I= google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/grpc/cmd/grpc_server/main.go b/grpc/cmd/grpc_server/main.go index d3368c2..908e080 100644 --- a/grpc/cmd/grpc_server/main.go +++ b/grpc/cmd/grpc_server/main.go @@ -2,9 +2,9 @@ package main import ( "context" - "database/sql" "flag" "fmt" + "github.com/jackc/pgx/v5" "google.golang.org/grpc" "google.golang.org/grpc/reflection" "log" @@ -12,7 +12,6 @@ import ( "time" "github.com/AndreiMartynenko/chat-server/grpc/pkg/chat_v1" - "github.com/golang/protobuf/ptypes/empty" ) const ( @@ -118,6 +117,7 @@ func main() { } */ +/* func (srv *server) Create(ctx context.Context, req *chat_v1.CreateNewChatRequest) (*chat_v1.CreateNewChatResponse, error) { ctx, cancel := context.WithTimeout(ctx, dbTimeout) defer cancel() @@ -219,3 +219,5 @@ func (srv *server) SendMessage(ctx context.Context, req *chat_v1.SendMessageRequ // return db, nil // } + +*/ diff --git a/internal/api/chat_v1/chat_api.proto b/internal/api/chat_v1/chat_api.proto new file mode 100644 index 0000000..5a4d3d2 --- /dev/null +++ b/internal/api/chat_v1/chat_api.proto @@ -0,0 +1,46 @@ +syntax = "proto3"; + +package chat_v1; + +import "google/protobuf/timestamp.proto"; +import "google/protobuf/empty.proto"; + +option go_package = "github.com/AndreiMartynenko/chat-server/api_config/pkg/chat_v1;chat_v1"; + +service ChatAPIServices { + rpc Create (CreateNewChatRequest) returns (CreateNewChatResponse); + rpc Delete (DeleteChatRequest) returns (DeleteChatResponse); + rpc SendMessage (SendMessageRequest) returns (SendMessageResponse); +} + +// Create NewChat Request +message CreateNewChatRequest { + repeated string usernames = 1; +} + +// Create NewChat Response +message CreateNewChatResponse { + int64 id = 1; +} + +// Delete Chat Request +message DeleteChatRequest { + int64 id = 1; +} + +message DeleteChatResponse { + google.protobuf.Empty delete_response = 1; +} + +// SendMessage Request +message SendMessageRequest { + string from = 1; + string text = 2; + google.protobuf.Timestamp timestamp = 3; + int64 chat_id = 4; +} + +// SendMessage Response +message SendMessageResponse { + google.protobuf.Empty send_message_response = 1; +} diff --git a/internal/config/config.go b/internal/config/config.go new file mode 100644 index 0000000..bd42c32 --- /dev/null +++ b/internal/config/config.go @@ -0,0 +1,14 @@ +package config + +import "github.com/joho/godotenv" + +//Load env file + +func Load(path string) error { + err := godotenv.Load(path) + if err != nil { + return err + } + + return nil +}