Skip to content

Commit ddaaf74

Browse files
committed
♻️ refactor: updated codebase and upgraded deps #4 #2
1 parent 87f9e36 commit ddaaf74

File tree

6 files changed

+22
-24
lines changed

6 files changed

+22
-24
lines changed

go.mod

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@ go 1.20
55
require (
66
github.com/jmoiron/sqlx v1.3.5
77
github.com/lib/pq v1.10.9
8-
github.com/sivaosorg/govm v1.2.6
8+
github.com/sivaosorg/govm v1.2.8
99
)
1010

1111
require (
12-
github.com/fatih/color v1.15.0 // indirect
12+
github.com/fatih/color v1.16.0 // indirect
1313
github.com/json-iterator/go v1.1.12 // indirect
1414
github.com/mattn/go-colorable v0.1.13 // indirect
15-
github.com/mattn/go-isatty v0.0.17 // indirect
16-
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
15+
github.com/mattn/go-isatty v0.0.20 // indirect
16+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
1717
github.com/modern-go/reflect2 v1.0.2 // indirect
1818
github.com/natefinch/lumberjack v2.0.0+incompatible // indirect
1919
github.com/sirupsen/logrus v1.9.3 // indirect
20-
golang.org/x/sys v0.12.0 // indirect
20+
golang.org/x/sys v0.15.0 // indirect
2121
gopkg.in/guregu/null.v3 v3.5.0
2222
)

go.sum

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8
22
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
33
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
44
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
5-
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
6-
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
5+
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
6+
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
77
github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE=
88
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
99
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
@@ -17,12 +17,13 @@ github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
1717
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
1818
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
1919
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
20-
github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng=
21-
github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
20+
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
21+
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
2222
github.com/mattn/go-sqlite3 v1.14.6 h1:dNPt6NO46WmLVt2DLNpwczCmdV5boIZ6g/tlDrlRUbg=
2323
github.com/mattn/go-sqlite3 v1.14.6/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
24-
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
2524
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
25+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
26+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
2627
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
2728
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
2829
github.com/natefinch/lumberjack v2.0.0+incompatible h1:4QJd3OLAMgj7ph+yZTuX13Ld4UpgHp07nNdFX7mqFfM=
@@ -31,16 +32,17 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
3132
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
3233
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
3334
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
34-
github.com/sivaosorg/govm v1.2.6 h1:BCUCNk/yy/rFZ+clMF7ftfw99ZQFO+4QSFV/xe2mWfA=
35-
github.com/sivaosorg/govm v1.2.6/go.mod h1:rXfPCNGc4ddPf1+VRX8Ytw/5xqehfPRrCr53Oi+cwpw=
35+
github.com/sivaosorg/govm v1.2.8 h1:SyVwq7PNUKQQNqI9PbjZ6zY9b33lks75y/qzAzxDNyI=
36+
github.com/sivaosorg/govm v1.2.8/go.mod h1:rXfPCNGc4ddPf1+VRX8Ytw/5xqehfPRrCr53Oi+cwpw=
3637
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
3738
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
3839
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
3940
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
4041
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
4142
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
42-
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
43-
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
43+
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
44+
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
45+
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
4446
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
4547
gopkg.in/guregu/null.v3 v3.5.0 h1:xTcasT8ETfMcUHn0zTvIYtQud/9Mx5dJqD554SZct0o=
4648
gopkg.in/guregu/null.v3 v3.5.0/go.mod h1:E4tX2Qe3h7QdL+uZ3a0vqvYwKQsRSQKM5V4YltdgH9Y=

postgresconn/postgresconn.go renamed to postgresconn.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ import (
1717
)
1818

1919
var (
20-
instance *Postgres
21-
_logger = logger.NewLogger()
20+
_logger = logger.NewLogger()
2221
)
2322

2423
func NewPostgres() *Postgres {
@@ -54,16 +53,13 @@ func (p *Postgres) GetConn() *sqlx.DB {
5453
}
5554

5655
func NewClient(config postgres.PostgresConfig) (*Postgres, dbx.Dbx) {
56+
instance := NewPostgres()
5757
s := dbx.NewDbx().SetDatabase(config.Database)
5858
if !config.IsEnabled {
5959
s.SetConnected(false).
6060
SetMessage("Postgres unavailable").
6161
SetError(fmt.Errorf(s.Message))
62-
instance = NewPostgres().SetState(*s)
63-
return instance, *s
64-
}
65-
if instance != nil {
66-
s.SetConnected(true)
62+
instance.SetState(*s)
6763
return instance, *s
6864
}
6965
stringConn := fmt.Sprintf("host=%s port=%d user=%s dbname=%s password=%s sslmode=%s",
@@ -74,23 +70,23 @@ func NewClient(config postgres.PostgresConfig) (*Postgres, dbx.Dbx) {
7470
client, err := sqlx.Open(common.EntryKeyPostgres, stringConn)
7571
if err != nil {
7672
s.SetError(err).SetConnected(false).SetMessage(err.Error())
77-
instance = NewPostgres().SetState(*s)
73+
instance.SetState(*s)
7874
return instance, *s
7975
}
8076
ctx, cancel := context.WithTimeout(context.Background(), config.Timeout)
8177
defer cancel()
8278
err = client.PingContext(ctx)
8379
if err != nil {
8480
s.SetError(err).SetConnected(false).SetMessage(err.Error())
85-
instance = NewPostgres().SetState(*s)
81+
instance.SetState(*s)
8682
return instance, *s
8783
}
8884
if config.DebugMode {
8985
_logger.Info(fmt.Sprintf("Connected successfully to postgres database %s:%d/%s", config.Host, config.Port, config.Database))
9086
}
9187
client.SetMaxIdleConns(config.MaxIdleConn)
9288
client.SetMaxOpenConns(config.MaxOpenConn)
93-
instance = NewPostgres().SetConn(client)
89+
instance.SetConn(client)
9490
s.SetConnected(true).SetMessage("Connected successfully").SetNewInstance(true).SetPid(os.Getpid())
9591
if config.DebugMode {
9692
callback.MeasureTime(func() {
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)