Skip to content
Open
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ go.work.sum
*.env
**/vendor.protogen

**/certificate/keys
**/certificate/keys

*.log
10 changes: 9 additions & 1 deletion libraries/cache_client/go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
module github.com/Genvekt/cli-chat/libraries/cache_client

replace github.com/Genvekt/cli-chat/libraries/logger => ../../libraries/logger

go 1.22.5

require github.com/gomodule/redigo v1.9.2
require (
github.com/Genvekt/cli-chat/libraries/logger v0.0.0-00010101000000-000000000000
github.com/gomodule/redigo v1.9.2
go.uber.org/zap v1.27.0
)

require go.uber.org/multierr v1.10.0 // indirect
6 changes: 6 additions & 0 deletions libraries/cache_client/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,11 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ=
go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
8 changes: 5 additions & 3 deletions libraries/cache_client/pkg/cache/redis/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package redis

import (
"context"
"log"
"time"

"github.com/gomodule/redigo/redis"
"go.uber.org/zap"

"github.com/Genvekt/cli-chat/libraries/logger/pkg/logger"

"github.com/Genvekt/cli-chat/libraries/cache_client/pkg/cache"
"github.com/Genvekt/cli-chat/libraries/cache_client/pkg/config"
Expand Down Expand Up @@ -151,7 +153,7 @@ func (c *client) execute(ctx context.Context, handler handler) error {
defer func() {
err = conn.Close()
if err != nil {
log.Printf("failed to close redis connection: %v\n", err)
logger.Error("failed to close redis connection", zap.Error(err))
}
}()

Expand All @@ -169,7 +171,7 @@ func (c *client) getConnect(ctx context.Context) (redis.Conn, error) {

conn, err := c.pool.GetContext(getConnTimeoutCtx)
if err != nil {
log.Printf("failed to get redis connection: %v\n", err)
logger.Error("failed to get redis connection", zap.Error(err))

_ = conn.Close()
return nil, err
Expand Down
9 changes: 9 additions & 0 deletions libraries/closer/go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
module github.com/Genvekt/cli-chat/libraries/closer

replace github.com/Genvekt/cli-chat/libraries/logger => ../../libraries/logger

go 1.22.5

require github.com/Genvekt/cli-chat/libraries/logger v0.0.0-00010101000000-000000000000

require (
go.uber.org/multierr v1.10.0 // indirect
go.uber.org/zap v1.27.0 // indirect
)
14 changes: 14 additions & 0 deletions libraries/closer/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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/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/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ=
go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
7 changes: 5 additions & 2 deletions libraries/closer/pkg/closer/closer.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package closer

import (
"fmt"
"os"
"os/signal"
"sync"

"go.uber.org/zap"

"github.com/Genvekt/cli-chat/libraries/logger/pkg/logger"
)

var globalCloser = New()
Expand Down Expand Up @@ -77,7 +80,7 @@ func (c *Closer) CloseAll() {

for i := 0; i < cap(errs); i++ {
if err := <-errs; err != nil {
fmt.Println("closer func returned error:", err)
logger.Error("closer func returned error", zap.Error(err))
}
}
})
Expand Down
5 changes: 5 additions & 0 deletions libraries/db_client/go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
module github.com/Genvekt/cli-chat/libraries/db_client

replace github.com/Genvekt/cli-chat/libraries/logger => ../../libraries/logger

go 1.22.5

require (
github.com/Genvekt/cli-chat/libraries/logger v0.0.0-00010101000000-000000000000
github.com/georgysavva/scany v1.2.2
github.com/gojuno/minimock/v3 v3.3.13
github.com/jackc/pgconn v1.14.3
Expand All @@ -20,6 +23,8 @@ require (
github.com/jackc/pgtype v1.14.0 // indirect
github.com/jackc/puddle v1.3.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
go.uber.org/multierr v1.10.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/crypto v0.20.0 // indirect
golang.org/x/text v0.14.0 // indirect
)
6 changes: 6 additions & 0 deletions libraries/db_client/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,19 @@ go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4=
go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU=
go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ=
go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA=
go.uber.org/zap v1.9.1/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM=
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190411191339-88737f569e3a/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE=
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
Expand Down
18 changes: 7 additions & 11 deletions libraries/db_client/pkg/db/pg/pg.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package pg

import (
"context"
"fmt"
"log"

"github.com/georgysavva/scany/pgxscan"
"github.com/jackc/pgconn"
"github.com/jackc/pgx/v4"
"github.com/jackc/pgx/v4/pgxpool"
"go.uber.org/zap"

"github.com/Genvekt/cli-chat/libraries/logger/pkg/logger"

"github.com/Genvekt/cli-chat/libraries/db_client/pkg/db/prettier"

Expand Down Expand Up @@ -36,8 +37,6 @@ func NewDB(dbc *pgxpool.Pool) *pg {

// ScanOneContext selects one row and parses it into provided type
func (p *pg) ScanOneContext(ctx context.Context, dest interface{}, q db.Query, args ...interface{}) error {
logQuery(ctx, q, args...)

row, err := p.QueryContext(ctx, q, args...)
if err != nil {
return err
Expand All @@ -48,8 +47,6 @@ func (p *pg) ScanOneContext(ctx context.Context, dest interface{}, q db.Query, a

// ScanAllContext selects several rows and parses them into provided type
func (p *pg) ScanAllContext(ctx context.Context, dest interface{}, q db.Query, args ...interface{}) error {
logQuery(ctx, q, args...)

rows, err := p.QueryContext(ctx, q, args...)
if err != nil {
return err
Expand Down Expand Up @@ -114,11 +111,10 @@ func MakeContextTx(ctx context.Context, tx pgx.Tx) context.Context {
return context.WithValue(ctx, TxKey, tx)
}

func logQuery(ctx context.Context, q db.Query, args ...interface{}) {
func logQuery(_ context.Context, q db.Query, args ...interface{}) {
prettyQuery := prettier.Pretty(q.QueryRaw, prettier.PlaceholderDollar, args...)
log.Println(
ctx,
fmt.Sprintf("sql: %s", q.Name),
fmt.Sprintf("query: %s", prettyQuery),
logger.Debug("postgres query",
zap.String("sql", q.Name),
zap.String("query", prettyQuery),
)
}
9 changes: 8 additions & 1 deletion libraries/kafka/go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
module github.com/Genvekt/cli-chat/libraries/kafka

replace github.com/Genvekt/cli-chat/libraries/logger => ../../libraries/logger

go 1.22.5

require github.com/IBM/sarama v1.43.2
require (
github.com/Genvekt/cli-chat/libraries/logger v0.0.0-00010101000000-000000000000
github.com/IBM/sarama v1.43.2
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
Expand All @@ -21,6 +26,8 @@ require (
github.com/klauspost/compress v1.17.8 // indirect
github.com/pierrec/lz4/v4 v4.1.21 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
go.uber.org/multierr v1.10.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/net v0.24.0 // indirect
)
6 changes: 6 additions & 0 deletions libraries/kafka/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o
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=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ=
go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58=
Expand Down
4 changes: 2 additions & 2 deletions libraries/kafka/pkg/kafka/consumer/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package consumer
import (
"context"
"errors"
"log"
"strings"

"github.com/IBM/sarama"

"github.com/Genvekt/cli-chat/libraries/kafka/pkg/kafka"
"github.com/Genvekt/cli-chat/libraries/logger/pkg/logger"
)

var _ kafka.Consumer[sarama.ConsumerMessage] = (*kafkaConsumer)(nil)
Expand Down Expand Up @@ -56,6 +56,6 @@ func (c *kafkaConsumer) consume(ctx context.Context, topicName string) error {
return ctx.Err()
}

log.Printf("rebalancing...\n")
logger.Info("rebalancing kafka consumer..")
}
}
22 changes: 16 additions & 6 deletions libraries/kafka/pkg/kafka/consumer/message_handler.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package consumer

import (
"log"

"github.com/IBM/sarama"
"go.uber.org/zap"

"github.com/Genvekt/cli-chat/libraries/logger/pkg/logger"

"github.com/Genvekt/cli-chat/libraries/kafka/pkg/kafka"
)
Expand Down Expand Up @@ -37,15 +38,24 @@ func (c *GroupHandler) ConsumeClaim(session sarama.ConsumerGroupSession, claim s
select {
case message, ok := <-claim.Messages():
if !ok {
log.Printf("message channel was closed\n")
logger.Error("kafka message channel was closed")
return nil
}

log.Printf("message claimed: value = %s, timestamp = %v, topic = %s\n", string(message.Value), message.Timestamp, message.Topic)
logger.Debug("kafka message claimed",
zap.String("message", string(message.Value)),
zap.Time("ts", message.Timestamp),
zap.String("topic", message.Topic),
)

err := c.msgHandler(session.Context(), message)
if err != nil {
log.Printf("error handling message: %v\n", err)
logger.Error("error handling kafka message",
zap.String("message", string(message.Value)),
zap.Time("ts", message.Timestamp),
zap.String("topic", message.Topic),
zap.Error(err),
)
continue
}

Expand All @@ -55,7 +65,7 @@ func (c *GroupHandler) ConsumeClaim(session sarama.ConsumerGroupSession, claim s
// В противном случае возникнет `ErrRebalanceInProgress` или `read tcp <ip>:<port>: i/o timeout` при перебалансировке кафки. см.:
// https://github.com/IBM/sarama/issues/1192
case <-session.Context().Done():
log.Printf("session context done\n")
logger.Warn("kafka session context done")
return nil
}
}
Expand Down
10 changes: 7 additions & 3 deletions libraries/kafka/pkg/kafka/producer/producer.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package producer

import (
"log"

"github.com/IBM/sarama"
"go.uber.org/zap"

"github.com/Genvekt/cli-chat/libraries/kafka/pkg/kafka"
"github.com/Genvekt/cli-chat/libraries/logger/pkg/logger"
)

var _ kafka.Producer[sarama.ProducerMessage] = (*kafkaProducer)(nil)
Expand All @@ -27,7 +27,11 @@ func (p *kafkaProducer) SendMessage(msg *sarama.ProducerMessage) error {
return err
}

log.Printf("message sent to partition %d with offset %d\n", partition, offset)
logger.Debug("kafka message sent",
zap.Int32("partition", partition),
zap.Int64("offset", offset),
zap.String("topic", msg.Topic),
)

return nil
}
Expand Down
7 changes: 7 additions & 0 deletions libraries/logger/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module github.com/Genvekt/cli-chat/libraries/logger

go 1.22.5

require go.uber.org/zap v1.27.0

require go.uber.org/multierr v1.10.0 // indirect
14 changes: 14 additions & 0 deletions libraries/logger/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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/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/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ=
go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Loading