From bdb88ea74f67f84c7bdf12a3d212853ab42c0616 Mon Sep 17 00:00:00 2001 From: alex Date: Fri, 17 Feb 2023 08:25:49 +0100 Subject: [PATCH] changed logger to go-cnj-helper loggeR --- go.mod | 27 +++++++----- go.sum | 85 +++++++++++++----------------------- main.go | 12 ++--- modules/config/config.go | 6 +-- modules/rabbitmq/helper.go | 47 ++++++++++---------- modules/rabbitmq/rabbitmq.go | 38 ++++++++-------- modules/redis/redis.go | 12 ++--- modules/scylladb/scylladb.go | 6 +-- modules/structs/socket.go | 8 ++-- modules/utils/utils.go | 8 ++-- socketserver/hub.go | 28 ++++++------ socketserver/server.go | 6 +-- 12 files changed, 128 insertions(+), 155 deletions(-) diff --git a/go.mod b/go.mod index f958784..52dbdcd 100644 --- a/go.mod +++ b/go.mod @@ -3,32 +3,35 @@ module clickandjoin.app/websocketserver go 1.19 require ( - git.clickandjoin.umbach.dev/ClickandJoin/go-rabbitmq-client v1.0.24 // indirect + git.clickandjoin.umbach.dev/ClickandJoin/go-cnj-helper v1.0.36 + github.com/gocql/gocql v1.3.1 + github.com/gofiber/fiber/v2 v2.40.1 + github.com/gofiber/websocket/v2 v2.1.2 + github.com/google/uuid v1.3.0 + github.com/rabbitmq/amqp091-go v1.5.0 + github.com/redis/go-redis/v9 v9.0.2 + github.com/scylladb/gocqlx/v2 v2.7.0 + gopkg.in/yaml.v2 v2.4.0 +) + +require ( github.com/andybalholm/brotli v1.0.4 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect github.com/fasthttp/websocket v1.5.0 // indirect - github.com/gocql/gocql v1.3.1 // indirect - github.com/gofiber/fiber/v2 v2.40.1 // indirect - github.com/gofiber/websocket/v2 v2.1.2 // indirect github.com/golang/snappy v0.0.4 // indirect - github.com/google/uuid v1.3.0 // indirect github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed // indirect github.com/klauspost/compress v1.15.12 // indirect github.com/mattn/go-colorable v0.1.13 // indirect - github.com/mattn/go-isatty v0.0.16 // indirect + github.com/mattn/go-isatty v0.0.17 // indirect github.com/mattn/go-runewidth v0.0.14 // indirect - github.com/rabbitmq/amqp091-go v1.5.0 // indirect - github.com/redis/go-redis/v9 v9.0.2 // indirect github.com/rivo/uniseg v0.4.3 // indirect + github.com/rs/zerolog v1.29.0 // indirect github.com/savsgio/gotils v0.0.0-20220530130905-52f3993e8d6d // indirect github.com/scylladb/go-reflectx v1.0.1 // indirect - github.com/scylladb/gocqlx/v2 v2.7.0 // indirect - github.com/sirupsen/logrus v1.9.0 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/fasthttp v1.43.0 // indirect github.com/valyala/tcplisten v1.0.0 // indirect - golang.org/x/sys v0.3.0 // indirect + golang.org/x/sys v0.5.0 // indirect gopkg.in/inf.v0 v0.9.1 // indirect - gopkg.in/yaml.v2 v2.4.0 // indirect ) diff --git a/go.sum b/go.sum index ec4ba12..a162fdf 100644 --- a/go.sum +++ b/go.sum @@ -1,59 +1,25 @@ -git.clickandjoin.umbach.dev/ClickandJoin/go-rabbitmq-client v1.0.4 h1:LdnXOQ+rxyb3F0UsUB8PCe2rj13HF7rPU9/AI6XEE2Y= -git.clickandjoin.umbach.dev/ClickandJoin/go-rabbitmq-client v1.0.4/go.mod h1:TnJVKLDZ8l/2HFeU6yzSGrxa1A9g4IpXlpLMqbgxnvo= -git.clickandjoin.umbach.dev/ClickandJoin/go-rabbitmq-client v1.0.5 h1:zDfrB0gutr3XOHBLbWjH1D51d+4QLgr8VNbGYbBCkbg= -git.clickandjoin.umbach.dev/ClickandJoin/go-rabbitmq-client v1.0.5/go.mod h1:TnJVKLDZ8l/2HFeU6yzSGrxa1A9g4IpXlpLMqbgxnvo= -git.clickandjoin.umbach.dev/ClickandJoin/go-rabbitmq-client v1.0.6 h1:RLJUVs8EfmhlU9IWHTpqnd/65m58yloJ8vb7geHFOOU= -git.clickandjoin.umbach.dev/ClickandJoin/go-rabbitmq-client v1.0.6/go.mod h1:TnJVKLDZ8l/2HFeU6yzSGrxa1A9g4IpXlpLMqbgxnvo= -git.clickandjoin.umbach.dev/ClickandJoin/go-rabbitmq-client v1.0.7 h1:PLdOzcnNxyrnHOg8pRGUJ9lZ+YIB/J16Vspuoytqx3I= -git.clickandjoin.umbach.dev/ClickandJoin/go-rabbitmq-client v1.0.7/go.mod h1:TnJVKLDZ8l/2HFeU6yzSGrxa1A9g4IpXlpLMqbgxnvo= -git.clickandjoin.umbach.dev/ClickandJoin/go-rabbitmq-client v1.0.8 h1:uMFmtiaOy8jiqW0HpZ9/9O2tpXplvOjYXIB/spuDib4= -git.clickandjoin.umbach.dev/ClickandJoin/go-rabbitmq-client v1.0.8/go.mod h1:TnJVKLDZ8l/2HFeU6yzSGrxa1A9g4IpXlpLMqbgxnvo= -git.clickandjoin.umbach.dev/ClickandJoin/go-rabbitmq-client v1.0.9 h1:yU7apejSLPdNyUNi/k6/Ix+QbSjyDLMgxsX2r9dFPrM= -git.clickandjoin.umbach.dev/ClickandJoin/go-rabbitmq-client v1.0.9/go.mod h1:TnJVKLDZ8l/2HFeU6yzSGrxa1A9g4IpXlpLMqbgxnvo= -git.clickandjoin.umbach.dev/ClickandJoin/go-rabbitmq-client v1.0.10 h1:lzYHPbLKuSe6Uh7fifvRcWy/6ZkszZ9/vAKrhHsBRE0= -git.clickandjoin.umbach.dev/ClickandJoin/go-rabbitmq-client v1.0.10/go.mod h1:TnJVKLDZ8l/2HFeU6yzSGrxa1A9g4IpXlpLMqbgxnvo= -git.clickandjoin.umbach.dev/ClickandJoin/go-rabbitmq-client v1.0.11 h1:CcdPpf2DcdZiCJ1oGj4ExN3VGMeubmZBdjVmLAFQUdA= -git.clickandjoin.umbach.dev/ClickandJoin/go-rabbitmq-client v1.0.11/go.mod h1:TnJVKLDZ8l/2HFeU6yzSGrxa1A9g4IpXlpLMqbgxnvo= -git.clickandjoin.umbach.dev/ClickandJoin/go-rabbitmq-client v1.0.12 h1:/KZI3TdUGp8kMb+0xbafvvnvU3lorieJetnKE8KMEmE= -git.clickandjoin.umbach.dev/ClickandJoin/go-rabbitmq-client v1.0.12/go.mod h1:TnJVKLDZ8l/2HFeU6yzSGrxa1A9g4IpXlpLMqbgxnvo= -git.clickandjoin.umbach.dev/ClickandJoin/go-rabbitmq-client v1.0.13 h1:IKEIiXplAyutn/tMUjLkF5lbfmeWpL9rMcLYaMS0uDM= -git.clickandjoin.umbach.dev/ClickandJoin/go-rabbitmq-client v1.0.13/go.mod h1:TnJVKLDZ8l/2HFeU6yzSGrxa1A9g4IpXlpLMqbgxnvo= -git.clickandjoin.umbach.dev/ClickandJoin/go-rabbitmq-client v1.0.14 h1:lfjHLJVILSYhHSIMensVOqlhUrAmISSmEEtpZh8QJAk= -git.clickandjoin.umbach.dev/ClickandJoin/go-rabbitmq-client v1.0.14/go.mod h1:KPbHNtFhttE/TtXZcorq6LKpCigkTaF0qzmB2p7nFsg= -git.clickandjoin.umbach.dev/ClickandJoin/go-rabbitmq-client v1.0.15 h1:QVZrkx+/gTt/E7DtGYwGnI9hQ66/D/F3YWwFdBPdtyg= -git.clickandjoin.umbach.dev/ClickandJoin/go-rabbitmq-client v1.0.15/go.mod h1:KPbHNtFhttE/TtXZcorq6LKpCigkTaF0qzmB2p7nFsg= -git.clickandjoin.umbach.dev/ClickandJoin/go-rabbitmq-client v1.0.16 h1:i9+wrkOQQbhuRU1xMaWTr2Y4JFdOQamTS/BZO8pCMjc= -git.clickandjoin.umbach.dev/ClickandJoin/go-rabbitmq-client v1.0.16/go.mod h1:KPbHNtFhttE/TtXZcorq6LKpCigkTaF0qzmB2p7nFsg= -git.clickandjoin.umbach.dev/ClickandJoin/go-rabbitmq-client v1.0.17 h1:Xh62QbcYLj/07r2hoR+Dz9K0vkbuP8oZ2NdspCfXPmc= -git.clickandjoin.umbach.dev/ClickandJoin/go-rabbitmq-client v1.0.17/go.mod h1:KPbHNtFhttE/TtXZcorq6LKpCigkTaF0qzmB2p7nFsg= -git.clickandjoin.umbach.dev/ClickandJoin/go-rabbitmq-client v1.0.18 h1:7WzhKv+b/leJoqa9h/kPlEcN3zijHXD88aPYtCboWhY= -git.clickandjoin.umbach.dev/ClickandJoin/go-rabbitmq-client v1.0.18/go.mod h1:KPbHNtFhttE/TtXZcorq6LKpCigkTaF0qzmB2p7nFsg= -git.clickandjoin.umbach.dev/ClickandJoin/go-rabbitmq-client v1.0.19 h1:RDvCD1EtTMe+eDWitGnyA6DwlmO10NqfXLRvGw1Ieho= -git.clickandjoin.umbach.dev/ClickandJoin/go-rabbitmq-client v1.0.19/go.mod h1:KPbHNtFhttE/TtXZcorq6LKpCigkTaF0qzmB2p7nFsg= -git.clickandjoin.umbach.dev/ClickandJoin/go-rabbitmq-client v1.0.20 h1:0fFXnoqdnzXxmLRBf3Rnp9UTuUT0zmrnIxO7OA+IZao= -git.clickandjoin.umbach.dev/ClickandJoin/go-rabbitmq-client v1.0.20/go.mod h1:KPbHNtFhttE/TtXZcorq6LKpCigkTaF0qzmB2p7nFsg= -git.clickandjoin.umbach.dev/ClickandJoin/go-rabbitmq-client v1.0.21 h1:6VgGO8GsrPtBfS6tcamw2OFRt4XplIKAY6zpgNbCvdg= -git.clickandjoin.umbach.dev/ClickandJoin/go-rabbitmq-client v1.0.21/go.mod h1:KPbHNtFhttE/TtXZcorq6LKpCigkTaF0qzmB2p7nFsg= -git.clickandjoin.umbach.dev/ClickandJoin/go-rabbitmq-client v1.0.22 h1:26wm+XTVNsoQxg8RHzkwS/s5ZKSjTvjQXg2GTM7Pwgw= -git.clickandjoin.umbach.dev/ClickandJoin/go-rabbitmq-client v1.0.22/go.mod h1:KPbHNtFhttE/TtXZcorq6LKpCigkTaF0qzmB2p7nFsg= -git.clickandjoin.umbach.dev/ClickandJoin/go-rabbitmq-client v1.0.23 h1:FYMFWE9gXAXtvLzyVmv9yp/AmQos1OfTuVZy6DnQrEw= -git.clickandjoin.umbach.dev/ClickandJoin/go-rabbitmq-client v1.0.23/go.mod h1:KPbHNtFhttE/TtXZcorq6LKpCigkTaF0qzmB2p7nFsg= -git.clickandjoin.umbach.dev/ClickandJoin/go-rabbitmq-client v1.0.24 h1:rvBwQLc5keM6kkAGL9qNQiOlvT5GDfgnYDn3viHVDR8= -git.clickandjoin.umbach.dev/ClickandJoin/go-rabbitmq-client v1.0.24/go.mod h1:KPbHNtFhttE/TtXZcorq6LKpCigkTaF0qzmB2p7nFsg= +git.clickandjoin.umbach.dev/ClickandJoin/go-cnj-helper v1.0.36 h1:tqx39cmvtID3lbjvUbN6Vv2Xt16fXQSwnxiw4esMqnQ= +git.clickandjoin.umbach.dev/ClickandJoin/go-cnj-helper v1.0.36/go.mod h1:RnqJsFYGR0cdxbeQjB1dDlr/MeKgnMkc7XoZtFDhMbo= github.com/andybalholm/brotli v1.0.4 h1:V7DdXeJtZscaqfNuAdSRuRFzuiKlHSC/Zh3zl9qY3JY= github.com/andybalholm/brotli v1.0.4/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig= +github.com/bitly/go-hostpool v0.0.0-20171023180738-a3a6125de932 h1:mXoPYz/Ul5HYEDvkta6I8/rnYM5gSdSV2tJ6XbZuEtY= github.com/bitly/go-hostpool v0.0.0-20171023180738-a3a6125de932/go.mod h1:NOuUCSz6Q9T7+igc/hlvDOUdtWKryOrtFyIVABv/p7k= +github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY= github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4= +github.com/bsm/ginkgo/v2 v2.5.0 h1:aOAnND1T40wEdAtkGSkvSICWeQ8L3UASX7YVCqQx+eQ= +github.com/bsm/gomega v1.20.0 h1:JhAwLmtRzXFTx2AkALSLa8ijZafntmhSoU63Ok18Uq8= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= github.com/fasthttp/websocket v1.5.0 h1:B4zbe3xXyvIdnqjOZrafVFklCUq5ZLo/TqCt5JA1wLE= github.com/fasthttp/websocket v1.5.0/go.mod h1:n0BlOQvJdPbTuBkZT0O5+jk/sp/1/VCzquR1BehI2F4= github.com/gocql/gocql v1.3.1 h1:BTwM4rux+ah5G3oH6/MQa+tur/TDd/XAAOXDxBBs7rg= github.com/gocql/gocql v1.3.1/go.mod h1:3gM2c4D3AnkISwBxGnMMsS8Oy4y2lhbPRsH4xnJrHG8= +github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/gofiber/fiber/v2 v2.40.1 h1:pc7n9VVpGIqNsvg9IPLQhyFEMJL8gCs1kneH5D1pIl4= github.com/gofiber/fiber/v2 v2.40.1/go.mod h1:Gko04sLksnHbzLSRBFWPFdzM9Ws9pRxvvIaohJK1dsk= github.com/gofiber/websocket/v2 v2.1.2 h1:EulKyLB/fJgui5+6c8irwEnYQ9FRsrLZfkrq9OfTDGc= @@ -61,33 +27,42 @@ github.com/gofiber/websocket/v2 v2.1.2/go.mod h1:S+sKWo0xeC7Wnz5h4/8f6D/NxsrLFId github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/google/go-cmp v0.5.4 h1:L8R9j+yAqZuZjsqh/z+F1NCffTKKLShY6zXTItVIZ8M= github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed h1:5upAirOpQc1Q53c0bnx2ufif5kANL7bfZWcc6VJWJd8= github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed/go.mod h1:tMWxXQ9wFIaZeTI9F+hmhFiGpFmhOHzyShyFUhRm0H4= github.com/klauspost/compress v1.14.1/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= -github.com/klauspost/compress v1.15.9 h1:wKRjX6JRtDdrE9qwa4b/Cip7ACOshUI4smpCQanqjSY= github.com/klauspost/compress v1.15.9/go.mod h1:PhcZ0MbTNciWF3rruxRgKxI5NkcHHrHUDtV4Yw2GlzU= github.com/klauspost/compress v1.15.12 h1:YClS/PImqYbn+UILDnqxQCZ3RehC9N318SU3kElDUEM= github.com/klauspost/compress v1.15.12/go.mod h1:QPwzmACJjUTFsnSHH934V6woptycfrDDJnH7hvFVbGM= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= 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 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ= +github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng= +github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWVwUuU= github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +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/rabbitmq/amqp091-go v1.5.0 h1:VouyHPBu1CrKyJVfteGknGOGCzmOz0zcv/tONLkb7rg= github.com/rabbitmq/amqp091-go v1.5.0/go.mod h1:JsV0ofX5f1nwOGafb8L5rBItt9GyhfQfcJj+oyz0dGg= github.com/redis/go-redis/v9 v9.0.2 h1:BA426Zqe/7r56kCcvxYLWe1mkaz71LKF77GwgFzSxfE= github.com/redis/go-redis/v9 v9.0.2/go.mod h1:/xDTe9EF1LM61hek62Poq2nzQSGj0xSrEtEHbBQevps= -github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.4.3 h1:utMvzDsuh3suAEnhH0RdHmoPbU648o6CvXxTx4SBMOw= github.com/rivo/uniseg v0.4.3/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= +github.com/rs/xid v1.4.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= +github.com/rs/zerolog v1.29.0 h1:Zes4hju04hjbvkVkOhdl2HpZa+0PmVwigmo8XoORE5w= +github.com/rs/zerolog v1.29.0/go.mod h1:NILgTygv/Uej1ra5XxGf82ZFSLk58MFGAUS2o6usyD0= github.com/savsgio/gotils v0.0.0-20211223103454-d0aaa54c5899/go.mod h1:oejLrk1Y/5zOF+c/aHtXqn3TFlzzbAgPWg8zBiAHDas= github.com/savsgio/gotils v0.0.0-20220530130905-52f3993e8d6d h1:Q+gqLBOPkFGHyCJxXMRqtUgUbTjI8/Ze8vu8GGyNFwo= github.com/savsgio/gotils v0.0.0-20220530130905-52f3993e8d6d/go.mod h1:Gy+0tqhJvgGlqnTF8CVGP0AaGRjwBtXs/a5PA0Y3+A4= @@ -95,21 +70,20 @@ github.com/scylladb/go-reflectx v1.0.1 h1:b917wZM7189pZdlND9PbIJ6NQxfDPfBvUaQ7cj github.com/scylladb/go-reflectx v1.0.1/go.mod h1:rWnOfDIRWBGN0miMLIcoPt/Dhi2doCMZqwMCJ3KupFc= github.com/scylladb/gocqlx/v2 v2.7.0 h1:/w1VeJHCEAsg9eTculTvIS9eIe/VmEu0clhlH1CF7lc= github.com/scylladb/gocqlx/v2 v2.7.0/go.mod h1:jKhM0/LkEAhEOSwd10TCMQdlC5x8aEzK7cXjQcPyMJ0= -github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= -github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= 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= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= github.com/valyala/fasthttp v1.33.0/go.mod h1:KJRK/MXx0J+yd0c5hlR+s1tIHD72sniU8ZJjl97LIw4= -github.com/valyala/fasthttp v1.41.0 h1:zeR0Z1my1wDHTRiamBCXVglQdbUwgb9uWG3k1HQz6jY= github.com/valyala/fasthttp v1.41.0/go.mod h1:f6VbjjoI3z1NDOZOv17o6RvtRSWxC77seBFc2uWtgiY= github.com/valyala/fasthttp v1.43.0 h1:Gy4sb32C98fbzVWZlTM1oTMdLWGyvxR03VhM6cBIU4g= github.com/valyala/fasthttp v1.43.0/go.mod h1:f6VbjjoI3z1NDOZOv17o6RvtRSWxC77seBFc2uWtgiY= github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8= github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= +go.uber.org/goleak v1.1.12 h1:gZAh5/EyT/HQwlpkCy6wTpqfH9H8Lz8zbm3dZh+OyzA= go.uber.org/goleak v1.1.12/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= @@ -125,6 +99,7 @@ golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qx golang.org/x/net v0.0.0-20220111093109-d55c255bac03/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220906165146-f3363e06e74c/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -133,14 +108,13 @@ golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220111092808-5a964db01320/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ= -golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab h1:2QkjZIsXupsJbJIdSjjUOgWK3aEtzyuh2mPt3l/CkeU= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ= -golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -153,11 +127,14 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc= gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= 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/main.go b/main.go index 68364a7..90bdd3a 100644 --- a/main.go +++ b/main.go @@ -11,20 +11,16 @@ import ( "clickandjoin.app/websocketserver/modules/structs" "clickandjoin.app/websocketserver/modules/utils" "clickandjoin.app/websocketserver/socketserver" + gocnjhelper "git.clickandjoin.umbach.dev/ClickandJoin/go-cnj-helper" "github.com/gofiber/fiber/v2" "github.com/gofiber/websocket/v2" - "github.com/sirupsen/logrus" ) func init() { config.LoadConfig() - if config.Cfg.Debug { - logrus.SetLevel(logrus.DebugLevel) - } - - logrus.Println("Debug:", config.Cfg.Debug) + gocnjhelper.InitLogger(config.Cfg.Debug, true, true) scylladb.InitDatabase() @@ -58,7 +54,7 @@ func main() { q := scylladb.Session.Query(scylladb.WebSocketSessions.Get("id", "user_id")).BindStruct(foundWsSession) if err := q.GetRelease(&foundWsSession); err != nil { - logrus.Errorln("Failed to find ws session:", wsSessionId, "err:", err) + gocnjhelper.LogDebugf("Failed to find ws session: %s, err: %s", wsSessionId, err) return c.SendStatus(fiber.StatusUnauthorized) } @@ -78,7 +74,7 @@ func main() { socketserver.WebSocketServer(app) if len(os.Args) < 2 { - logrus.Fatalln("Please specify port") + gocnjhelper.LogFatal("Please specify port") } app.Listen("127.0.0.1:" + os.Args[1]) diff --git a/modules/config/config.go b/modules/config/config.go index a263879..d887025 100644 --- a/modules/config/config.go +++ b/modules/config/config.go @@ -3,7 +3,7 @@ package config import ( "os" - "github.com/sirupsen/logrus" + gocnjhelper "git.clickandjoin.umbach.dev/ClickandJoin/go-cnj-helper" "gopkg.in/yaml.v2" ) @@ -32,10 +32,10 @@ func LoadConfig() { data, err := os.ReadFile("config.yml") if err != nil { - logrus.Fatalln("Failed to read config file, err:", err) + gocnjhelper.LogFatalf("Failed to read config file, err: %s", err) } if err := yaml.Unmarshal(data, &Cfg); err != nil { - logrus.Fatalln("Failed to unmarshal config file, err:", err) + gocnjhelper.LogFatalf("Failed to unmarshal config file, err: %s", err) } } diff --git a/modules/rabbitmq/helper.go b/modules/rabbitmq/helper.go index 46bb6d6..79e7d86 100644 --- a/modules/rabbitmq/helper.go +++ b/modules/rabbitmq/helper.go @@ -8,26 +8,25 @@ import ( "clickandjoin.app/websocketserver/modules/structs" "clickandjoin.app/websocketserver/modules/utils" "clickandjoin.app/websocketserver/socketclients" - gorabbitmqclient "git.clickandjoin.umbach.dev/ClickandJoin/go-rabbitmq-client" + gocnjhelper "git.clickandjoin.umbach.dev/ClickandJoin/go-cnj-helper" "github.com/google/uuid" amqp "github.com/rabbitmq/amqp091-go" - "github.com/sirupsen/logrus" ) func PublishClientMessage(rabbitMqMessage structs.RabbitMqMessage) error { msg, err := json.Marshal(rabbitMqMessage) if err != nil { - logrus.Errorln("Failed to marshal rabbitMqMessage, err:", err) + gocnjhelper.LogErrorf("Failed to marshal rabbitMqMessage, err: %S", err) return err } - logrus.Println("SENT MSG:", rabbitMqMessage.Rec, string(msg)) + gocnjhelper.LogDebugf("SENT MSG: %s %s", rabbitMqMessage.Rec, string(msg)) err = WebsocketClient.PushExchangeMessage(rabbitMqMessage.Rec, msg) if err != nil { - logrus.Errorln("Failed to publish client msg, err:", err) + gocnjhelper.LogErrorf("Failed to publish client msg, err: %s", err) return err } @@ -39,7 +38,7 @@ func CreateWSClientBinding(socketClient *structs.SocketClient, id string) (err e msgs, err := createWSClientQueueAndBindingConsumer(socketClient, id) if err != nil { - logrus.Errorln("Failed to create ws client queue and binding consumer, err:", err) + gocnjhelper.LogErrorf("Failed to create ws client queue and binding consumer, err: %s", err) return err } @@ -52,7 +51,7 @@ func CreateWSClientBinding(socketClient *structs.SocketClient, id string) (err e for { select { case <-ctx.Done(): - logrus.Println("DONE!") + gocnjhelper.LogDebug("DONE!") return case <-WebSocketChannelClosedChannel: // This case handles the event of closed channel e.g. abnormal shutdown @@ -65,7 +64,7 @@ func CreateWSClientBinding(socketClient *structs.SocketClient, id string) (err e continue } - logrus.Debugln("Re-set ws client channel", socketClient.RabbitMqConsumerId) + gocnjhelper.LogDebugf("Re-set ws client channel %s", socketClient.RabbitMqConsumerId) // Re-set channel to receive notifications // The library closes this channel after abnormal shutdown @@ -78,13 +77,13 @@ func CreateWSClientBinding(socketClient *structs.SocketClient, id string) (err e err = utils.UnmarshalReceivedMessage(msg.Body, &receivedMessage) if err != nil { - logrus.Errorln("Failed to unmarshal received msg, err:", err) + gocnjhelper.LogErrorf("Failed to unmarshal received msg, err: %s", err) } - logrus.Debugln("RABBITMQ RECEIVED MESSAGE:", receivedMessage) + gocnjhelper.LogDebugf("RABBITMQ RECEIVED MESSAGE: %s", receivedMessage) if receivedMessage.Cmd == utils.RabbitMqWsCmdInternalDeleteWebSocketSession { - logrus.Println("here", fmt.Sprintf("%v", receivedMessage.Body)) + gocnjhelper.LogDebugf("here %s", fmt.Sprintf("%v", receivedMessage.Body)) /* if socketClient, ok := cache.GetSocketClient(fmt.Sprintf("%v", receivedMessage.Body)); ok { logrus.Println("here deleted", socketClient) @@ -96,7 +95,7 @@ func CreateWSClientBinding(socketClient *structs.SocketClient, id string) (err e err = socketClient.SendMessage(structs.SendSocketMessage{Cmd: receivedMessage.Cmd, Body: receivedMessage.Body}) if err != nil { - logrus.Errorln("Failed to send message to client, err:", err) + gocnjhelper.LogErrorf("Failed to send message to client, err: %s", err) } } @@ -114,7 +113,7 @@ func CreateWSClientBinding(socketClient *structs.SocketClient, id string) (err e } func createWSClientQueueAndBindingConsumer(socketClient *structs.SocketClient, id string) (msgs <-chan amqp.Delivery, err error) { - q, err := WebsocketClient.QueueDeclare(gorabbitmqclient.QueueDeclareSettings{ + q, err := WebsocketClient.QueueDeclare(gocnjhelper.QueueDeclareSettings{ Name: "", Durable: false, DeleteWhenUnused: false, @@ -133,7 +132,7 @@ func createWSClientQueueAndBindingConsumer(socketClient *structs.SocketClient, i // store queue name in the client to delete it when the client disconnects from the websocket socketClient.RabbitMqQueueName = q.Name - err = WebsocketClient.QueueBind(gorabbitmqclient.QueueBindSettings{ + err = WebsocketClient.QueueBind(gocnjhelper.QueueBindSettings{ QueueName: q.Name, RoutingKey: id, Exchange: exchangeWebsocketMessages, @@ -142,11 +141,11 @@ func createWSClientQueueAndBindingConsumer(socketClient *structs.SocketClient, i }) if err != nil { - logrus.Errorln("Failed to bind queue, err:", err) + gocnjhelper.LogErrorf("Failed to bind queue, err: %s", err) return msgs, err } - return WebsocketClient.ConsumeChannelMessages(gorabbitmqclient.ChannelConsumeSettings{ + return WebsocketClient.ConsumeChannelMessages(gocnjhelper.ChannelConsumeSettings{ QueueName: q.Name, Consumer: socketClient.RabbitMqConsumerId, AutoAck: true, @@ -162,7 +161,7 @@ func DeleteWSClient(consumerId string, qName string) error { err := WebsocketClient.Channel.Cancel(consumerId, false) if err != nil { - logrus.Errorln("Failed to delete consumer, err:", err) + gocnjhelper.LogErrorf("Failed to delete consumer, err: %s", err) return err } @@ -170,11 +169,11 @@ func DeleteWSClient(consumerId string, qName string) error { _, err = WebsocketClient.Channel.QueueDelete(qName, false, true, false) if err != nil { - logrus.Errorln("Failed to delete queue, err:", err) + gocnjhelper.LogErrorf("Failed to delete queue, err: %s", err) return err } - logrus.Println("deleted", consumerId, qName) + gocnjhelper.LogDebugf("deleted %s %s", consumerId, qName) return nil } @@ -183,7 +182,7 @@ func ApiBroadcastMessagesHandling() { msgs, err := apiBroadcastMessagesConsumer() if err != nil { - logrus.Errorln("Failed to create api broadcast message consumer, err:", err) + gocnjhelper.LogErrorf("Failed to create api broadcast message consumer, err: %s", err) return } @@ -204,7 +203,7 @@ func ApiBroadcastMessagesHandling() { continue } - logrus.Debugln("Re-set api broadcast channel") + gocnjhelper.LogDebug("Re-set api broadcast channel") // Re-set channel to receive notifications // The library closes this channel after abnormal shutdown @@ -217,10 +216,10 @@ func ApiBroadcastMessagesHandling() { err = utils.UnmarshalReceivedMessage(msg.Body, &receivedMessage) if err != nil { - logrus.Errorln("Failed to unmarshal received msg, err:", err) + gocnjhelper.LogErrorf("Failed to unmarshal received msg, err: %s", err) } - logrus.Debugln("RABBITMQ RECEIVED BROADCAST MESSAGE:", receivedMessage) + gocnjhelper.LogDebugf("RABBITMQ RECEIVED BROADCAST MESSAGE: %s", receivedMessage) socketclients.BroadcastMessage(structs.SendSocketMessage{Cmd: receivedMessage.Cmd, Body: receivedMessage.Body}) } @@ -229,7 +228,7 @@ func ApiBroadcastMessagesHandling() { } func apiBroadcastMessagesConsumer() (msgs <-chan amqp.Delivery, err error) { - return ApiBroadcastClient.ConsumeChannelMessages(gorabbitmqclient.ChannelConsumeSettings{ + return ApiBroadcastClient.ConsumeChannelMessages(gocnjhelper.ChannelConsumeSettings{ QueueName: ApiBroadcastClient.AssignedQueueName, Consumer: "", AutoAck: true, diff --git a/modules/rabbitmq/rabbitmq.go b/modules/rabbitmq/rabbitmq.go index 60a8a52..25b3eac 100644 --- a/modules/rabbitmq/rabbitmq.go +++ b/modules/rabbitmq/rabbitmq.go @@ -4,7 +4,7 @@ import ( "time" "clickandjoin.app/websocketserver/modules/config" - gorabbitmqclient "git.clickandjoin.umbach.dev/ClickandJoin/go-rabbitmq-client" + gocnjhelper "git.clickandjoin.umbach.dev/ClickandJoin/go-cnj-helper" amqp "github.com/rabbitmq/amqp091-go" ) @@ -14,8 +14,8 @@ const ( ) var ( - WebsocketClient *gorabbitmqclient.Client - ApiBroadcastClient *gorabbitmqclient.Client + WebsocketClient *gocnjhelper.Client + ApiBroadcastClient *gocnjhelper.Client ConnectionAddress string WebSocketChannelClosedChannel chan *amqp.Error // informs when the connection has been lost ) @@ -23,14 +23,13 @@ var ( func Init() { cfg := config.Cfg - ConnectionAddress = gorabbitmqclient.GetConnectionString(cfg.RabbitMq.Username, cfg.RabbitMq.Password, cfg.RabbitMq.Host) + ConnectionAddress = gocnjhelper.GetConnectionString(cfg.RabbitMq.Username, cfg.RabbitMq.Password, cfg.RabbitMq.Host) /* * websocketserver messages */ - WebsocketClient = gorabbitmqclient.NewClient( - cfg.Debug, - gorabbitmqclient.ExchangeSettings{ + WebsocketClient = gocnjhelper.NewClient( + gocnjhelper.ExchangeSettings{ Enabled: true, Name: exchangeWebsocketMessages, Type: "direct", @@ -39,15 +38,15 @@ func Init() { Internal: false, NoWait: false, Arguments: nil, - ExchangePublishSettings: gorabbitmqclient.ExchangePublishSettings{ + ExchangePublishSettings: gocnjhelper.ExchangePublishSettings{ Mandatory: false, Immediate: false, - ContentType: gorabbitmqclient.ContentTypeJson, + ContentType: gocnjhelper.ContentTypeJson, }, }, - gorabbitmqclient.QueueSettings{}, - gorabbitmqclient.ChannelQosSettingsDefault, - gorabbitmqclient.Config{ + gocnjhelper.QueueSettings{}, + gocnjhelper.ChannelQosSettingsDefault, + gocnjhelper.Config{ ReconnectDelay: 1 * time.Second, ReInitDelay: 1 * time.Second, ResendDelay: 5 * time.Second, @@ -58,10 +57,9 @@ func Init() { * api broadcast messages */ - ApiBroadcastClient = gorabbitmqclient.NewClient( - cfg.Debug, - gorabbitmqclient.ExchangeSettings{}, - gorabbitmqclient.QueueSettings{ + ApiBroadcastClient = gocnjhelper.NewClient( + gocnjhelper.ExchangeSettings{}, + gocnjhelper.QueueSettings{ Enabled: true, Name: "", Durable: false, @@ -69,17 +67,17 @@ func Init() { Exclusive: true, NoWait: false, Arguments: nil, - QueueBindSettings: gorabbitmqclient.QueueBindSettings{ + QueueBindSettings: gocnjhelper.QueueBindSettings{ Enabled: true, - QueueName: gorabbitmqclient.SetQueueNameToAutomaticallyAssignedQueueName, + QueueName: gocnjhelper.SetQueueNameToAutomaticallyAssignedQueueName, RoutingKey: "", Exchange: exchangeBroadcastMessages, NoWait: false, Arguments: nil, }, }, - gorabbitmqclient.ChannelQosSettingsDefault, - gorabbitmqclient.Config{ + gocnjhelper.ChannelQosSettingsDefault, + gocnjhelper.Config{ ReconnectDelay: 1 * time.Second, ReInitDelay: 1 * time.Second, ResendDelay: 5 * time.Second, diff --git a/modules/redis/redis.go b/modules/redis/redis.go index cc9b00b..368777f 100644 --- a/modules/redis/redis.go +++ b/modules/redis/redis.go @@ -3,8 +3,8 @@ package redis import ( "context" + gocnjhelper "git.clickandjoin.umbach.dev/ClickandJoin/go-cnj-helper" "github.com/redis/go-redis/v9" - "github.com/sirupsen/logrus" ) var ctx = context.Background() @@ -20,26 +20,26 @@ func Init() { err := rdb.Ping(ctx).Err() if err != nil { - logrus.Fatalln("Redis ping failed") + gocnjhelper.LogFatal("Redis ping failed") } } func AddUserWebSocketSessionId(userId string, wsSessionId string) { cmd := rdb.LPush(ctx, userId, wsSessionId) - logrus.Println("b", cmd) + gocnjhelper.LogDebugf("b %s", cmd) } func RemoveUserWebSocketSessionId(userId string, wsSessionId string) { cmd := rdb.LRem(ctx, userId, -1, wsSessionId) - logrus.Println("rem", cmd) + gocnjhelper.LogDebugf("rem %s", cmd) } func IsUserConnectedToAnyWebSocketServer(userId string) bool { cmd := rdb.Exists(ctx, userId) - logrus.Println("exists b", cmd) + gocnjhelper.LogDebugf("exists b %s", cmd) return cmd.Val() == 1 } @@ -47,7 +47,7 @@ func IsUserConnectedToAnyWebSocketServer(userId string) bool { func ExistsUserWebSocketSessionId(userId string, wsSessionId string) bool { wsSessions := rdb.LRange(ctx, userId, 0, -1) - logrus.Println("found ws", wsSessions.Val()) + gocnjhelper.LogDebugf("found ws %s", wsSessions.Val()) return isWsSessionIdInList(wsSessions.Val(), wsSessionId) } diff --git a/modules/scylladb/scylladb.go b/modules/scylladb/scylladb.go index fec43d8..c584a19 100644 --- a/modules/scylladb/scylladb.go +++ b/modules/scylladb/scylladb.go @@ -2,9 +2,9 @@ package scylladb import ( "clickandjoin.app/websocketserver/modules/config" + gocnjhelper "git.clickandjoin.umbach.dev/ClickandJoin/go-cnj-helper" "github.com/gocql/gocql" "github.com/scylladb/gocqlx/v2" - "github.com/sirupsen/logrus" ) var Session gocqlx.Session @@ -25,8 +25,8 @@ func InitDatabase() { Session, err = gocqlx.WrapSession(Cluster.CreateSession()) if err != nil { - logrus.Fatal(err) + gocnjhelper.LogFatal(err.Error()) } - logrus.Info("Database connected") + gocnjhelper.LogDebug("Database connected") } diff --git a/modules/structs/socket.go b/modules/structs/socket.go index 7a5477a..2a6bfe4 100644 --- a/modules/structs/socket.go +++ b/modules/structs/socket.go @@ -7,8 +7,8 @@ import ( "sync" "clickandjoin.app/websocketserver/modules/utils" + gocnjhelper "git.clickandjoin.umbach.dev/ClickandJoin/go-cnj-helper" "github.com/gofiber/websocket/v2" - "github.com/sirupsen/logrus" ) type SocketClient struct { @@ -43,7 +43,7 @@ func (socketClient *SocketClient) writeMessage(messageType int, message SendSock marshaledMessage, err = json.Marshal(message) if err != nil { - logrus.Errorln("Failed to marshal ws message, err:", err) + gocnjhelper.LogErrorf("Failed to marshal ws message, err: %s", err) return err } } @@ -52,14 +52,14 @@ func (socketClient *SocketClient) writeMessage(messageType int, message SendSock defer socketClient.connMu.Unlock() if socketClient.Conn == nil { - logrus.Errorln("Failed to ws message because conn is nil") + gocnjhelper.LogError("Failed to ws message because conn is nil") return errors.New("ws client conn is nil") } err = socketClient.Conn.WriteMessage(messageType, marshaledMessage) if err != nil { - logrus.Errorln("Failed to write ws message, err:", err) + gocnjhelper.LogErrorf("Failed to write ws message, err: %s", err) return err } diff --git a/modules/utils/utils.go b/modules/utils/utils.go index f6fec11..ec61898 100644 --- a/modules/utils/utils.go +++ b/modules/utils/utils.go @@ -3,14 +3,14 @@ package utils import ( "encoding/json" - "github.com/sirupsen/logrus" + gocnjhelper "git.clickandjoin.umbach.dev/ClickandJoin/go-cnj-helper" ) func MarshalMessage(message any) (marshaledMessage []byte, err error) { marshaledMessage, err = json.Marshal(message) if err != nil { - logrus.Errorln("Failed to marshal send message, err:", err) + gocnjhelper.LogErrorf("Failed to marshal send message, err: %s", err) return nil, err } @@ -18,11 +18,11 @@ func MarshalMessage(message any) (marshaledMessage []byte, err error) { } func UnmarshalReceivedMessage(body []byte, message any) error { - logrus.Println("UnmarshalReceivedMessage", string(body)) + gocnjhelper.LogDebugf("UnmarshalReceivedMessage %s", string(body)) err := json.Unmarshal(body, &message) if err != nil { - logrus.Errorln("Failed to unmarshal received message, err:", err) + gocnjhelper.LogDebugf("Failed to unmarshal received message, err: %s", err) return err } diff --git a/socketserver/hub.go b/socketserver/hub.go index a21c91e..f2bd895 100644 --- a/socketserver/hub.go +++ b/socketserver/hub.go @@ -9,8 +9,8 @@ import ( "clickandjoin.app/websocketserver/modules/structs" "clickandjoin.app/websocketserver/modules/utils" "clickandjoin.app/websocketserver/socketclients" + gocnjhelper "git.clickandjoin.umbach.dev/ClickandJoin/go-cnj-helper" "github.com/gofiber/websocket/v2" - "github.com/sirupsen/logrus" ) var register = make(chan *structs.SocketClient) @@ -26,13 +26,13 @@ func RunHub() { newSocketClient.UserId = userId - logrus.Println("clients:", len(cache.GetSocketClients()), cache.GetSocketClients()) + gocnjhelper.LogDebugf("clients: %d %s", len(cache.GetSocketClients()), cache.GetSocketClients()) if redis.ExistsUserWebSocketSessionId(userId, wsSessionId) { // kick out the other connected socket connections with this session - logrus.Println("ws id already in list") + gocnjhelper.LogDebug("ws id already in list") if socketClient, ok := socketclients.GetSocketClientByWsSessionId(wsSessionId); ok { - logrus.Println("sc", socketClient, ok) + gocnjhelper.LogDebugf("sc %s %s", socketClient, ok) // a socket client with this session is connected to this server socketClient.SendCloseMessage() @@ -52,13 +52,13 @@ func RunHub() { err := rabbitmq.CreateWSClientBinding(newSocketClient, userId) if err != nil { - logrus.Errorln("Failed to create client binding, err:", err) + gocnjhelper.LogErrorf("Failed to create client binding, err: %s", err) break } cache.AddSocketClient(wsSessionId, newSocketClient) - logrus.Debugln("REGISTER CLIENT:", wsSessionId) + gocnjhelper.LogDebugf("REGISTER CLIENT: %s", wsSessionId) // for testing if socketClient, ok := cache.GetSocketClient(wsSessionId); ok { @@ -71,10 +71,10 @@ func RunHub() { err := utils.UnmarshalReceivedMessage(data.Msg, &receivedMessage) if err != nil { - logrus.Errorln("Failed to unmarshal received msg, err:", err) + gocnjhelper.LogErrorf("Failed to unmarshal received msg, err: %s", err) } - logrus.Debugln("RECEIVED WEBSOCKET MESSAGE:", receivedMessage) + gocnjhelper.LogDebugf("RECEIVED WEBSOCKET MESSAGE: %s", receivedMessage) if len(receivedMessage.Rec) == utils.LenWebSocketSession { SendMessageToClient(receivedMessage.Rec, structs.SendSocketMessage{Cmd: receivedMessage.Cmd, Body: receivedMessage.Body}) @@ -83,7 +83,7 @@ func RunHub() { case connection := <-unregister: for id, client := range cache.GetSocketClients() { if connection == client.Conn { - logrus.Debugln("UNREGISTER CLIENT:", id) + gocnjhelper.LogDebugf("UNREGISTER CLIENT: %s", id) cache.DeleteClient(id) client.CancelFunc() @@ -98,23 +98,23 @@ func RunHub() { func SendMessageToClient(targetUserId string, msg structs.SendSocketMessage) { if isConnected, socketClients := socketclients.IsReceiverConnectedToThisServer(targetUserId); isConnected { // send message to target receiver which is connected to this server - logrus.Debugln("FORWARDING MESSAGE: receiver is connected to this server") + gocnjhelper.LogDebug("FORWARDING MESSAGE: receiver is connected to this server") for _, socketClient := range socketClients { - logrus.Println("send to ", socketClient.UserId) + gocnjhelper.LogDebugf("send to %s", socketClient.UserId) socketClient.SendMessage(msg) } } else { // send message to target receiver which is connected to any other server - logrus.Debugln("FORWARDING MESSAGE: receiver connected to other server") + gocnjhelper.LogDebug("FORWARDING MESSAGE: receiver connected to other server") if redis.IsUserConnectedToAnyWebSocketServer(targetUserId) { err := rabbitmq.PublishClientMessage(structs.RabbitMqMessage{Cmd: msg.Cmd, Rec: targetUserId, Body: msg.Body}) if err != nil { - logrus.Errorln("Failed to publish client message, err:", err) + gocnjhelper.LogErrorf("Failed to publish client message, err: %s", err) } } else { - logrus.Warnln("rec user not connected to any other websocket server") + gocnjhelper.LogDebug("rec user not connected to any other websocket server") } } } diff --git a/socketserver/server.go b/socketserver/server.go index 32eef4a..17e60e8 100644 --- a/socketserver/server.go +++ b/socketserver/server.go @@ -2,9 +2,9 @@ package socketserver import ( "clickandjoin.app/websocketserver/modules/structs" + gocnjhelper "git.clickandjoin.umbach.dev/ClickandJoin/go-cnj-helper" "github.com/gofiber/fiber/v2" "github.com/gofiber/websocket/v2" - "github.com/sirupsen/logrus" ) func WebSocketServer(app *fiber.App) { @@ -21,7 +21,7 @@ func WebSocketServer(app *fiber.App) { if err != nil { if websocket.IsUnexpectedCloseError(err, websocket.CloseGoingAway, websocket.CloseAbnormalClosure) { - logrus.Errorln("Read err:", err) + gocnjhelper.LogErrorf("Read err: %s", err) } return @@ -30,7 +30,7 @@ func WebSocketServer(app *fiber.App) { if messageType == websocket.TextMessage { broadcast <- structs.SocketMessage{Conn: c, Msg: msg} } else { - logrus.Println("websocket message received of type", messageType) + gocnjhelper.LogDebugf("websocket message received of type %s", messageType) } } }))