Skip to content

Commit 8b1536c

Browse files
committed
feat: updated new changes in gomora
1 parent 903c1b6 commit 8b1536c

File tree

9 files changed

+137
-23
lines changed

9 files changed

+137
-23
lines changed

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ up:
4343
docker compose down
4444
docker compose up -d --build
4545

46-
.PHONY: schema
47-
schema:
46+
.PHONY: migrate-schema
47+
migrate-schema:
4848
mkdir -p infrastructures/database/mysql/migrations
4949
migrate create -ext sql -dir infrastructures/database/mysql/migrations -seq ${NAME}
5050

go.mod

+15-5
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,37 @@ go 1.21
44

55
require (
66
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5
7-
github.com/go-chi/chi v1.5.4
7+
github.com/go-chi/chi/v5 v5.0.7
88
github.com/go-chi/cors v1.2.1
9+
github.com/go-chi/jwtauth/v5 v5.3.2
910
github.com/go-playground/validator/v10 v10.16.0
1011
github.com/go-sql-driver/mysql v1.7.0
1112
github.com/golang/protobuf v1.5.3
1213
github.com/jmoiron/sqlx v1.3.5
1314
github.com/joho/godotenv v1.5.1
1415
github.com/segmentio/ksuid v1.0.4
15-
golang.org/x/crypto v0.7.0
16+
golang.org/x/crypto v0.31.0
1617
google.golang.org/grpc v1.53.0
1718
google.golang.org/protobuf v1.30.0
1819
)
1920

2021
require (
22+
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
2123
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
2224
github.com/go-playground/locales v0.14.1 // indirect
2325
github.com/go-playground/universal-translator v0.18.1 // indirect
26+
github.com/goccy/go-json v0.10.3 // indirect
2427
github.com/leodido/go-urn v1.2.4 // indirect
28+
github.com/lestrrat-go/blackmagic v1.0.2 // indirect
29+
github.com/lestrrat-go/httpcc v1.0.1 // indirect
30+
github.com/lestrrat-go/httprc v1.0.6 // indirect
31+
github.com/lestrrat-go/iter v1.0.2 // indirect
32+
github.com/lestrrat-go/jwx/v2 v2.1.3 // indirect
33+
github.com/lestrrat-go/option v1.0.1 // indirect
34+
github.com/segmentio/asm v1.2.0 // indirect
2535
github.com/smartystreets/goconvey v1.6.4 // indirect
26-
golang.org/x/net v0.8.0 // indirect
27-
golang.org/x/sys v0.6.0 // indirect
28-
golang.org/x/text v0.8.0 // indirect
36+
golang.org/x/net v0.21.0 // indirect
37+
golang.org/x/sys v0.28.0 // indirect
38+
golang.org/x/text v0.21.0 // indirect
2939
google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4 // indirect
3040
)

go.sum

+35-13
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@ github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia
33
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
44
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
55
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
6+
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 h1:rpfIENRNNilwHwZeG5+P150SMrnNEcHYvcCuK6dPZSg=
7+
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0=
68
github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU=
79
github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA=
8-
github.com/go-chi/chi v1.5.4 h1:QHdzF2szwjqVV4wmByUnTcsbIg7UGaQ0tPF2t5GcAIs=
9-
github.com/go-chi/chi v1.5.4/go.mod h1:uaf8YgoFazUOkPBG7fxPftUylNumIev9awIWOENIuEg=
10+
github.com/go-chi/chi/v5 v5.0.7 h1:rDTPXLDHGATaeHvVlLcR4Qe0zftYethFucbjVQ1PxU8=
11+
github.com/go-chi/chi/v5 v5.0.7/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
1012
github.com/go-chi/cors v1.2.1 h1:xEC8UT3Rlp2QuWNEr4Fs/c2EAGVKBwy/1vHx3bppil4=
1113
github.com/go-chi/cors v1.2.1/go.mod h1:sSbTewc+6wYHBBCW7ytsFSn836hqM7JxpglAy2Vzc58=
14+
github.com/go-chi/jwtauth/v5 v5.3.2 h1:s+ON3ATyyMs3Me0kqyuua6Rwu+2zqIIkL0GCaMarwvs=
15+
github.com/go-chi/jwtauth/v5 v5.3.2/go.mod h1:O4QvPRuZLZghl9WvfVaON+ARfGzpD2PBX/QY5vUz7aQ=
1216
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
1317
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
1418
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
@@ -20,6 +24,8 @@ github.com/go-playground/validator/v10 v10.16.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QX
2024
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
2125
github.com/go-sql-driver/mysql v1.7.0 h1:ueSltNNllEqE3qcWBTD0iQd3IpL/6U+mJxLkazJ7YPc=
2226
github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
27+
github.com/goccy/go-json v0.10.3 h1:KZ5WoDbxAIgm2HNbYckL0se1fHD6rz5j4ywS6ebzDqA=
28+
github.com/goccy/go-json v0.10.3/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
2329
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
2430
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
2531
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
@@ -36,12 +42,26 @@ github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7
3642
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
3743
github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q=
3844
github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4=
45+
github.com/lestrrat-go/blackmagic v1.0.2 h1:Cg2gVSc9h7sz9NOByczrbUvLopQmXrfFx//N+AkAr5k=
46+
github.com/lestrrat-go/blackmagic v1.0.2/go.mod h1:UrEqBzIR2U6CnzVyUtfM6oZNMt/7O7Vohk2J0OGSAtU=
47+
github.com/lestrrat-go/httpcc v1.0.1 h1:ydWCStUeJLkpYyjLDHihupbn2tYmZ7m22BGkcvZZrIE=
48+
github.com/lestrrat-go/httpcc v1.0.1/go.mod h1:qiltp3Mt56+55GPVCbTdM9MlqhvzyuL6W/NMDA8vA5E=
49+
github.com/lestrrat-go/httprc v1.0.6 h1:qgmgIRhpvBqexMJjA/PmwSvhNk679oqD1RbovdCGW8k=
50+
github.com/lestrrat-go/httprc v1.0.6/go.mod h1:mwwz3JMTPBjHUkkDv/IGJ39aALInZLrhBp0X7KGUZlo=
51+
github.com/lestrrat-go/iter v1.0.2 h1:gMXo1q4c2pHmC3dn8LzRhJfP1ceCbgSiT9lUydIzltI=
52+
github.com/lestrrat-go/iter v1.0.2/go.mod h1:Momfcq3AnRlRjI5b5O8/G5/BvpzrhoFTZcn06fEOPt4=
53+
github.com/lestrrat-go/jwx/v2 v2.1.3 h1:Ud4lb2QuxRClYAmRleF50KrbKIoM1TddXgBrneT5/Jo=
54+
github.com/lestrrat-go/jwx/v2 v2.1.3/go.mod h1:q6uFgbgZfEmQrfJfrCo90QcQOcXFMfbI/fO0NqRtvZo=
55+
github.com/lestrrat-go/option v1.0.1 h1:oAzP2fvZGQKWkvHa1/SAcFolBEca1oN+mQ7eooNBEYU=
56+
github.com/lestrrat-go/option v1.0.1/go.mod h1:5ZHFbivi4xwXxhxY9XHDe2FHo6/Z7WWmtT7T5nBBp3I=
3957
github.com/lib/pq v1.2.0 h1:LXpIM/LZ5xGFhOpXAQUIMM1HdyqzVYM13zNdjCEEcA0=
4058
github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
4159
github.com/mattn/go-sqlite3 v1.14.6 h1:dNPt6NO46WmLVt2DLNpwczCmdV5boIZ6g/tlDrlRUbg=
4260
github.com/mattn/go-sqlite3 v1.14.6/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
4361
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
4462
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
63+
github.com/segmentio/asm v1.2.0 h1:9BQrFxC+YOHJlTlHGkTrFWf59nbL3XnCoFLTwDCI7ys=
64+
github.com/segmentio/asm v1.2.0/go.mod h1:BqMnlJP91P8d+4ibuonYZw9mfnzI9HfxselHZr5aAcs=
4565
github.com/segmentio/ksuid v1.0.4 h1:sBo2BdShXjmcugAMwjugoGUdUV0pcxY5mW4xKRn3v4c=
4666
github.com/segmentio/ksuid v1.0.4/go.mod h1:/XUiZBD3kVx5SmUOl55voK5yeAbBNNIed+2O73XgrPE=
4767
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
@@ -51,24 +71,26 @@ github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9
5171
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
5272
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
5373
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
74+
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
5475
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
5576
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
56-
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
5777
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
78+
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
79+
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
5880
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
59-
golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A=
60-
golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
81+
golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U=
82+
golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
6183
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
62-
golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ=
63-
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
84+
golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=
85+
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
6486
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
65-
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
66-
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
67-
golang.org/x/term v0.6.0 h1:clScbb1cHjoCkyRbWwBEUZ5H/tIFu5TAXIqaZD0Gcjw=
68-
golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U=
87+
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
88+
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
89+
golang.org/x/term v0.27.0 h1:WP60Sv1nlK1T6SupCHbXzSaN0b9wUmsPoRS9b61A23Q=
90+
golang.org/x/term v0.27.0/go.mod h1:iMsnZpn0cago0GOrHO2+Y7u7JPn5AylBrcoWkElMTSM=
6991
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
70-
golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68=
71-
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
92+
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
93+
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
7294
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
7395
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
7496
google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4 h1:DdoeryqhaXp1LtT/emMP1BRJPHHKFi5akj/nbx/zNTA=

infrastructures/database/mysql/MySQLDBHandler.go

+11
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,17 @@ type viaSSHDialer struct {
2525
client *ssh.Client
2626
}
2727

28+
// Begin starts a new transaction
29+
func (h *MySQLDBHandler) Begin() (*sqlx.Tx, error) {
30+
// begin transaction
31+
tx, err := h.Conn.Beginx()
32+
if err != nil {
33+
return nil, err
34+
}
35+
36+
return tx, nil
37+
}
38+
2839
// Connect opens a new connection to the mysql interface
2940
func (h *MySQLDBHandler) Connect(params types.ConnectionParams) error {
3041
if len(params.Dial) == 0 {

infrastructures/database/mysql/types/MySQLDBHandlerInterface.go

+7
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,18 @@ package types
22

33
import (
44
"database/sql"
5+
6+
"github.com/jmoiron/sqlx"
57
)
68

79
// MySQLDBHandlerInterface contains the implementable methods for the MySQL DB handler
810
type MySQLDBHandlerInterface interface {
11+
// Begin starts a new transaction
12+
Begin() (*sqlx.Tx, error)
13+
// Execute executes the mysql statement following NamedExec
914
Execute(stmt string, model interface{}) (sql.Result, error)
15+
// Query selects rows given by the sql statement
1016
Query(qstmt string, model interface{}, bindModel interface{}) error
17+
// QueryRow selects a row given by the sql statement
1118
QueryRow(qstmt string, model interface{}, bindModel interface{}) error
1219
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package jwt
2+
3+
import (
4+
"net/http"
5+
6+
"github.com/go-chi/jwtauth/v5"
7+
8+
"celeste/interfaces/http/rest/viewmodels"
9+
"celeste/internal/errors"
10+
)
11+
12+
// JWTAuthMiddleware handles JWT authentication custom errors
13+
func JWTAuthMiddleware(next http.Handler) http.Handler {
14+
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
15+
_, claims, err := jwtauth.FromContext(r.Context())
16+
if err != nil {
17+
var httpCode int
18+
var errorMsg string
19+
20+
switch err {
21+
case jwtauth.ErrExpired:
22+
httpCode = http.StatusUnauthorized
23+
errorMsg = "Token has expired."
24+
case jwtauth.ErrNoTokenFound:
25+
httpCode = http.StatusUnauthorized
26+
errorMsg = "No token found."
27+
case jwtauth.ErrUnauthorized:
28+
httpCode = http.StatusUnauthorized
29+
errorMsg = "Invalid token."
30+
default:
31+
httpCode = http.StatusUnauthorized
32+
errorMsg = "Invalid token"
33+
}
34+
35+
response := viewmodels.HTTPResponseVM{
36+
Status: httpCode,
37+
Success: false,
38+
Message: errorMsg,
39+
ErrorCode: errors.UnauthorizedAccess,
40+
}
41+
42+
response.JSON(w)
43+
return
44+
}
45+
46+
// if token is nil, creates unauthorized response
47+
if claims == nil {
48+
response := viewmodels.HTTPResponseVM{
49+
Status: http.StatusUnauthorized,
50+
Success: false,
51+
Message: "Invalid token",
52+
ErrorCode: errors.UnauthorizedAccess,
53+
}
54+
55+
response.JSON(w)
56+
return
57+
}
58+
59+
// if token is valid, proceeds to the next handler
60+
next.ServeHTTP(w, r)
61+
})
62+
}

interfaces/http/rest/router.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import (
1818
"strings"
1919
"sync"
2020

21-
"github.com/go-chi/chi"
22-
"github.com/go-chi/chi/middleware"
21+
"github.com/go-chi/chi/v5"
22+
"github.com/go-chi/chi/v5/middleware"
2323

2424
"celeste/interfaces/http/rest/middlewares/cors"
2525
"celeste/interfaces/http/rest/viewmodels"

internal/errors/constants.go

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ const (
55
DatabaseError string = "DATABASE_ERROR"
66
// DuplicateRecord is the code for duplicate records
77
DuplicateRecord string = "DUPLICATE_RECORD"
8+
// ForbiddenAccess is the code for forbidden access
9+
ForbiddenAccess string = "FORBIDDEN_ACCESS"
810
// HystrixTimeout is the code for hystrix timeouts
911
HystrixTimeout string = "HYSTRIX_TIMEOUT"
1012
// InvalidRequestPayload is the code for binding errors

module/user/interfaces/http/rest/UserQueryController.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"context"
55
"net/http"
66

7-
"github.com/go-chi/chi"
7+
"github.com/go-chi/chi/v5"
88

99
"celeste/interfaces/http/rest/viewmodels"
1010
"celeste/internal/errors"

0 commit comments

Comments
 (0)