Skip to content

Commit ae5274c

Browse files
chore: update config retrieve mechanism and sql base from sql to sqlx
1 parent 4282e86 commit ae5274c

File tree

13 files changed

+68
-61
lines changed

13 files changed

+68
-61
lines changed
File renamed without changes.

cmd/scheduler/.keep

Whitespace-only changes.

config/config-local.yaml.example

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
server:
2-
name: golang-clean-architecture
3-
version: "v0.0.1"
4-
rpc_port: 8080
5-
rest_port: 9090
6-
debug: false
7-
env: local
8-
read_time_out: 5s
9-
write_time_out: 5s
1+
Server:
2+
Name: golang-clean-architecture
3+
Version: "v0.0.1"
4+
RPCPort: 8080
5+
RESTPort: 9090
6+
Debug: false
7+
Env: local
8+
ReadTimeOut: 5s
9+
WriteTimeOut: 5s
1010

11-
database:
12-
host: localhost
13-
port: 3306
14-
name: users
15-
user: mysql
16-
password: pwd
11+
Database:
12+
Host: localhost
13+
Port: 3306
14+
Name: users
15+
User: mysql
16+
Password: pwd
1717

18-
authentication:
19-
key: DoWithLogic!@#
20-
secret_key: s3cr#tK3y!@#v001
21-
salt_key: s4ltK3y!@#ddv001
18+
Authentication:
19+
Key: DoWithLogic!@#
20+
SecretKey: s3cr#tK3y!@#v001
21+
SaltKey: s4ltK3y!@#ddv001

config/config.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,28 @@ type (
1515
}
1616

1717
DatabaseConfig struct {
18-
Host string `mapstructure:"host"`
19-
Port int `mapstructure:"port"`
20-
Name string `mapstructure:"name"`
21-
User string `mapstructure:"user"`
22-
Password string `mapstructure:"password"`
18+
Host string
19+
Port int
20+
Name string
21+
User string
22+
Password string
2323
}
2424

2525
ServerConfig struct {
26-
Name string `mapstructure:"name"`
27-
Version string `mapstructure:"version"`
28-
RPCPort string `mapstructure:"rpc_port"`
29-
RESTPort string `mapstructure:"rest_port"`
30-
Debug bool `mapstructure:"debug"`
31-
Environment string `mapstructure:"env"`
32-
ReadTimeout time.Duration `mapstructure:"read_time_out"`
33-
WriteTimeout time.Duration `mapstructure:"write_time_out"`
26+
Name string
27+
Version string
28+
RPCPort string
29+
RESTPort string
30+
Debug bool
31+
Environment string
32+
ReadTimeout time.Duration
33+
WriteTimeout time.Duration
3434
}
3535

3636
AuthenticationConfig struct {
37-
Key string `mapstructure:"key"`
38-
SecretKey string `mapstructure:"secret_key"`
39-
SaltKey string `mapstructure:"salt_key"`
37+
Key string
38+
SecretKey string
39+
SaltKey string
4040
}
4141
)
4242

internal/users/delivery/kafka/.keep

Whitespace-only changes.

internal/users/delivery/kafka/read.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

internal/users/delivery/rpc/.keep

Whitespace-only changes.

internal/users/delivery/rpc/read.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
package dtos
22

3-
import "github.com/invopop/validation"
3+
import (
4+
"github.com/DoWithLogic/golang-clean-architecture/pkg/apperror"
5+
"github.com/DoWithLogic/golang-clean-architecture/pkg/constant"
6+
"github.com/invopop/validation"
7+
)
48

59
type UpdateUserStatusRequest struct {
610
UserID int64 `json:"-"`
7-
Status int `json:"status"`
11+
Status string `json:"status"`
812
UpdateBy string `json:"-"`
913
}
1014

1115
func (ussp UpdateUserStatusRequest) Validate() error {
16+
if ussp.Status != constant.UserInactive && ussp.Status != constant.UserActive {
17+
return apperror.ErrStatusValue
18+
}
19+
1220
return validation.ValidateStruct(&ussp,
1321
validation.Field(&ussp.UserID, validation.NotNil),
1422
validation.Field(&ussp.UpdateBy, validation.NotNil),
15-
validation.Field(&ussp.Status, validation.Required),
1623
)
1724
}

internal/users/repository/repository.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func NewRepository(c *sqlx.DB, l *zerolog.Logger) Repository {
3737

3838
// Atomic implements vendor.Repository for transaction query
3939
func (r *repository) Atomic(ctx context.Context, opt *sql.TxOptions, repo func(tx Repository) error) error {
40-
txConn, err := r.db.BeginTx(ctx, opt)
40+
txConn, err := r.db.BeginTxx(ctx, opt)
4141
if err != nil {
4242
r.log.Z().Err(err).Msg("[repository]Atomic.BeginTxx")
4343

@@ -122,8 +122,8 @@ func (repo *repository) GetUserByID(ctx context.Context, userID int64, options .
122122
query += " FOR UPDATE"
123123
}
124124

125-
if err = new(datasource.DataSource).QuerySQL(repo.conn.QueryContext(ctx, query, args...)).Scan(row); err != nil {
126-
repo.log.Z().Err(err).Msg("[repository]GetUserByID.QueryContext")
125+
if err = new(datasource.DataSource).QuerySQL(repo.conn.QueryxContext(ctx, query, args...)).Scan(row); err != nil {
126+
repo.log.Z().Err(err).Msg("[repository]GetUserByID.QueryxContext")
127127
return userData, err
128128
}
129129

@@ -159,9 +159,9 @@ func (repo *repository) IsUserExist(ctx context.Context, email string) bool {
159159
}
160160
}
161161

162-
err := new(datasource.DataSource).QuerySQL(repo.conn.QueryContext(ctx, repository_query.IsUserExist, args...)).Scan(row)
162+
err := new(datasource.DataSource).QuerySQL(repo.conn.QueryxContext(ctx, repository_query.IsUserExist, args...)).Scan(row)
163163
if err != nil {
164-
repo.log.Z().Err(err).Msg("[repository]IsUserExist.QueryContext")
164+
repo.log.Z().Err(err).Msg("[repository]IsUserExist.QueryxContext")
165165

166166
return false
167167
}
@@ -182,9 +182,9 @@ func (repo *repository) GetUserByEmail(ctx context.Context, email string) (userD
182182
}
183183
}
184184

185-
err = new(datasource.DataSource).QuerySQL(repo.conn.QueryContext(ctx, repository_query.GetUserByEmail, args...)).Scan(row)
185+
err = new(datasource.DataSource).QuerySQL(repo.conn.QueryxContext(ctx, repository_query.GetUserByEmail, args...)).Scan(row)
186186
if err != nil {
187-
repo.log.Z().Err(err).Msg("[repository]GetUserByID.QueryContext")
187+
repo.log.Z().Err(err).Msg("[repository]GetUserByID.QueryxContext")
188188
return entities.Users{}, err
189189
}
190190

0 commit comments

Comments
 (0)