├── .env.example
├── .gitignore
├── Procfile
├── README.md
├── common
├── obj
│ └── obj.common.go
└── response
│ └── response.common.go
├── config
└── database.config.go
├── dto
├── login.dto.go
├── product.dto.go
├── register.dto.go
└── user.dto.go
├── entity
├── product.entity.go
└── user.entity.go
├── go.mod
├── go.sum
├── handler
└── v1
│ ├── auth.handler.go
│ ├── check.handler.go
│ ├── product.handler.go
│ └── user.handler.go
├── main.go
├── middleware
└── auth.middleware.go
├── repo
├── product.repo.go
└── user.repo.go
└── service
├── auth.service.go
├── jwt.service.go
├── product.service.go
├── product
└── product.response.go
├── user.service.go
└── user
└── user.response.go
/.env.example:
--------------------------------------------------------------------------------
1 | DB_USER=
2 | DB_PASSWORD=
3 | DB_NAME=
4 | DB_HOST=
5 | DB_PORT=
6 | JWT_SECRET=
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .env
2 |
--------------------------------------------------------------------------------
/Procfile:
--------------------------------------------------------------------------------
1 | web: golang_heroku
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # golang heroku deploy
2 | This is a simple restful api project that deployed to heroku. You can access it with this url:
3 | ```
4 | https://golang-heroku.herokuapp.com
5 | ```
6 |
7 | Find the tutorial here:
8 | ```
9 | https://www.youtube.com/watch?v=_EAkLIoMCNM
10 | ```
11 |
12 | # Documentation
13 | ## health
14 | to check current server is alive:
15 |
16 | GET
17 | ```
18 | https://golang-heroku.herokuapp.com/api/check/health
19 | ```
20 |
21 | Response (Status: 200)
22 | ```
23 | {
24 | message: "OK!"
25 | }
26 | ```
27 |
28 | ## register
29 | Registering a new user
30 |
31 | POST
32 | ```
33 | https://golang-heroku.herokuapp.com/api/auth/register
34 | ```
35 |
36 | Request Body
37 | ```
38 | {
39 | "name": "Prieyudha Akadita S",
40 | "email": "ydhnwb@gmail.com",
41 | "password": "yudhanewbie"
42 | }
43 | ```
44 |
45 | Response success (Status: 201)
46 | ```
47 | {
48 | "status": true,
49 | "message": "OK!",
50 | "errors": null,
51 | "data": {
52 | "id": 2,
53 | "name": "Prieyudha Akadita S",
54 | "email": "ydhnwb@gmail.com",
55 | "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiMiIsImV4cCI6MTY1MTgyMDAwMCwiaWF0IjoxNjIwMjg0MDAwLCJpc3MiOiJhZG1pbiJ9.HtnuWlBaevEO3fHAI4McH5W8axvw_3Og47RUI3m9IyI"
56 | }
57 | }
58 | ```
59 |
60 | Response error (Status : 400) [Depends on what error]
61 | ```
62 | {
63 | "status": false,
64 | "message": "Failed to process request",
65 | "errors": [
66 | "Key: 'RegisterRequest.Name' Error:Field validation for 'Name' failed on the 'required' tag"
67 | ],
68 | "data": {}
69 | }
70 | ```
71 |
72 | ## login
73 | Authenticate by email and password
74 |
75 | POST
76 | ```
77 | https://golang-heroku.herokuapp.com/api/auth/login
78 | ```
79 |
80 | Request body
81 | ```
82 | {
83 | "email": "yudhanewbie@gmail.com",
84 | "password": "yudhanewbie"
85 | }
86 | ```
87 |
88 | Response Success (Status: 200)
89 | ```
90 | {
91 | "status": true,
92 | "message": "OK!",
93 | "errors": null,
94 | "data": {
95 | "id": 1,
96 | "name": "Prieyudha Akadita S",
97 | "email": "yudhanewbie@gmail.com",
98 | "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiMSIsImV4cCI6MTY1MTgyMTQ0NiwiaWF0IjoxNjIwMjg1NDQ2LCJpc3MiOiJhZG1pbiJ9.2m-r1qrCXhNkAxzK-sb4hL0Pzat3zwOmzktES_uzwts"
99 | }
100 | }
101 | ```
102 |
103 | Response error, wrong credential (Status: 401)
104 | ```
105 | {
106 | "status": false,
107 | "message": "Failed to login",
108 | "errors": [
109 | "failed to login. check your credential"
110 | ],
111 | "data": {}
112 | }
113 | ```
114 |
115 |
116 | ## Get Profile
117 | Get current info from logged user
118 |
119 | GET
120 | ```
121 | https://golang-heroku.herokuapp.com/api/user/profile
122 | ```
123 |
124 | Headers
125 | ```
126 | Authorization: yourToken
127 | ```
128 |
129 | Response success (status: 200)
130 | ```
131 | {
132 | "status": true,
133 | "message": "OK",
134 | "errors": null,
135 | "data": {
136 | "id": 1,
137 | "name": "Prieyudha Akadita S",
138 | "email": "yudhanewbie@gmail.com"
139 | }
140 | }
141 | ```
142 |
143 | ## Update profile
144 | Update user data who logged in
145 |
146 | PUT
147 | ```
148 | https://golang-heroku.herokuapp.com/api/user/profile
149 | ```
150 |
151 | Headers
152 | ```
153 | Authorization: yourToken
154 | ```
155 |
156 | Request Body
157 | ```
158 | {
159 | "name": "Prieyudha Akadita S",
160 | "email": "ahmadalbar@gmail.com"
161 | }
162 | ```
163 |
164 | Response success (Status: 200)
165 | ```
166 | {
167 | "status": true,
168 | "message": "OK",
169 | "errors": null,
170 | "data": {
171 | "id": 1,
172 | "name": "Prieyudha Akadita S",
173 | "email": "ahmadalbar@gmail.com"
174 | }
175 | }
176 | ```
177 |
178 |
179 | =============================================
180 | ## All products (based on user who logged in)
181 | Only shows products by user who logged in
182 |
183 | GET
184 | ```
185 | https://golang-heroku.herokuapp.com/api/product
186 | ```
187 |
188 |
189 | Headers
190 | ```
191 | Authorization: yourToken
192 | ```
193 |
194 | Response success (Status: 200)
195 | ```
196 | {
197 | "status": true,
198 | "message": "OK!",
199 | "errors": null,
200 | "data": [
201 | {
202 | "id": 2,
203 | "product_name": "Xiaomi Redmi 10",
204 | "price": 3000,
205 | "user": {
206 | "id": 1,
207 | "name": "Prieyudha Akadita S",
208 | "email": "ahmadalbar@gmail.com"
209 | }
210 | },
211 | {
212 | "id": 3,
213 | "product_name": "Indomie Goreng",
214 | "price": 2500,
215 | "user": {
216 | "id": 1,
217 | "name": "Prieyudha Akadita S",
218 | "email": "ahmadalbar@gmail.com"
219 | }
220 | }
221 | ]
222 | }
223 | ```
224 |
225 | ## Create product
226 | Create a product with owner is the user who logged in
227 |
228 | POST
229 | ```
230 | https://golang-heroku.herokuapp.com/api/product
231 | ```
232 |
233 | Headers
234 | ```
235 | Authorization: yourToken
236 | ```
237 |
238 | Request body
239 | ```
240 | {
241 | "name": "Xiaomi Redmi 5",
242 | "price": 3000
243 | }
244 | ```
245 |
246 | Response success (Status: 201)
247 | ```
248 | {
249 | "status": true,
250 | "message": "OK!",
251 | "errors": null,
252 | "data": {
253 | "id": 1,
254 | "product_name": "Xiaomi Redmi 5",
255 | "price": 3000,
256 | "user": {
257 | "id": 1,
258 | "name": "Prieyudha Akadita S",
259 | "email": "ahmadalbar@gmail.com"
260 | }
261 | }
262 | }
263 | ```
264 |
265 | ## Find one product by id
266 | Find product by id
267 |
268 | GET
269 | ```
270 | https://golang-heroku.herokuapp.com/api/product/{id}
271 | ```
272 |
273 | Headers
274 | ```
275 | Authorization: yourToken
276 | ```
277 |
278 |
279 | Response success (Status: 200)
280 | ```
281 | {
282 | "status": true,
283 | "message": "OK!",
284 | "errors": null,
285 | "data": {
286 | "id": 1,
287 | "product_name": "Xiaomi Redmi 5",
288 | "price": 3000,
289 | "user": {
290 | "id": 1,
291 | "name": "Prieyudha Akadita S",
292 | "email": "ahmadalbar@gmail.com"
293 | }
294 | }
295 | }
296 | ```
297 |
298 | ## Update product
299 | You can only update your own product If you are trying to update someone else product, it will return error.
300 |
301 | PUT
302 | ```
303 | https://golang-heroku.herokuapp.com/api/product/{id}
304 | ```
305 |
306 | Request body
307 | ```
308 | {
309 | "name": "Xiaomi Redmi 5 Plus",
310 | "price": 5000
311 | }
312 | ```
313 |
314 | Response success (Status: 200)
315 | ```
316 | {
317 | "status": true,
318 | "message": "OK!",
319 | "errors": null,
320 | "data": {
321 | "id": 1,
322 | "product_name": "Xiaomi Redmi 5 Plus",
323 | "price": 5000,
324 | "user": {
325 | "id": 1,
326 | "name": "Prieyudha Akadita S",
327 | "email": "ahmadalbar@gmail.com"
328 | }
329 | }
330 | }
331 | ```
332 |
333 |
334 | ## Delete product
335 | You can only delete your own product
336 |
337 | DELETE
338 | ```
339 | https://golang-heroku.herokuapp.com/api/product/{id}
340 | ```
341 |
342 | Response success (Status: 200)
343 | ```
344 | {
345 | "status": true,
346 | "message": "OK!",
347 | "errors": null,
348 | "data": {}
349 | }
350 | ```
351 |
--------------------------------------------------------------------------------
/common/obj/obj.common.go:
--------------------------------------------------------------------------------
1 | package obj
2 |
3 | //EmptyObj object is used when data doesnt want to be null on json
4 | type EmptyObj struct{}
5 |
--------------------------------------------------------------------------------
/common/response/response.common.go:
--------------------------------------------------------------------------------
1 | package response
2 |
3 | import "strings"
4 |
5 | //Response is used for static shape json return
6 | type Response struct {
7 | Status bool `json:"status"`
8 | Message string `json:"message"`
9 | Errors interface{} `json:"errors"`
10 | Data interface{} `json:"data"`
11 | }
12 |
13 | //BuildResponse method is to inject data value to dynamic success response
14 | func BuildResponse(status bool, message string, data interface{}) Response {
15 | res := Response{
16 | Status: status,
17 | Message: message,
18 | Errors: nil,
19 | Data: data,
20 | }
21 | return res
22 | }
23 |
24 | //BuildErrorResponse method is to inject data value to dynamic failed response
25 | func BuildErrorResponse(message string, err string, data interface{}) Response {
26 | splittedError := strings.Split(err, "\n")
27 | res := Response{
28 | Status: false,
29 | Message: message,
30 | Errors: splittedError,
31 | Data: data,
32 | }
33 | return res
34 | }
35 |
--------------------------------------------------------------------------------
/config/database.config.go:
--------------------------------------------------------------------------------
1 | package config
2 |
3 | import (
4 | "fmt"
5 | "os"
6 |
7 | "github.com/ydhnwb/golang_heroku/entity"
8 | "gorm.io/driver/postgres"
9 | "gorm.io/gorm"
10 | )
11 |
12 | //SetupDatabaseConnection is creating a new connection to our database
13 | func SetupDatabaseConnection() *gorm.DB {
14 | // errEnv := godotenv.Load()
15 | // if errEnv != nil {
16 | // panic("Failed to load env file. Make sure .env file is exists!")
17 | // }
18 |
19 | dbUser := os.Getenv("DB_USER")
20 | dbPass := os.Getenv("DB_PASSWORD")
21 | dbHost := os.Getenv("DB_HOST")
22 | dbName := os.Getenv("DB_NAME")
23 | dbPort := os.Getenv("DB_PORT")
24 |
25 | dsn := fmt.Sprintf("host=%s user=%s password=%s port=%s dbname=%s sslmode=require TimeZone=Asia/Shanghai", dbHost, dbUser, dbPass, dbPort, dbName)
26 | db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})
27 | if err != nil {
28 | panic("Failed to create a connection to database")
29 | }
30 |
31 | db.AutoMigrate(&entity.User{}, &entity.Product{})
32 | println("Database connected!")
33 | return db
34 | }
35 |
36 | //CloseDatabaseConnection method is closing a connection between your app and your db
37 | func CloseDatabaseConnection(db *gorm.DB) {
38 | dbSQL, err := db.DB()
39 | if err != nil {
40 | panic("Failed to close connection from database")
41 | }
42 | dbSQL.Close()
43 | }
44 |
--------------------------------------------------------------------------------
/dto/login.dto.go:
--------------------------------------------------------------------------------
1 | package dto
2 |
3 | type LoginRequest struct {
4 | Email string `json:"email" form:"email" binding:"required,email"`
5 | Password string `json:"password" form:"password" binding:"required,min=6"`
6 | }
7 |
--------------------------------------------------------------------------------
/dto/product.dto.go:
--------------------------------------------------------------------------------
1 | package dto
2 |
3 | type CreateProductRequest struct {
4 | Name string `json:"name" form:"name" binding:"required,min=1"`
5 | Price uint64 `json:"price" form:"email" binding:"required"`
6 | }
7 |
8 | type UpdateProductRequest struct {
9 | ID int64 `json:"id" form:"id"`
10 | Name string `json:"name" form:"name" binding:"required,min=1"`
11 | Price uint64 `json:"price" form:"email" binding:"required"`
12 | }
13 |
--------------------------------------------------------------------------------
/dto/register.dto.go:
--------------------------------------------------------------------------------
1 | package dto
2 |
3 | type RegisterRequest struct {
4 | Name string `json:"name" form:"name" binding:"required,min=1"`
5 | Email string `json:"email" form:"email" binding:"required,email"`
6 | Password string `json:"password" form:"password" binding:"required,min=6"`
7 | }
8 |
--------------------------------------------------------------------------------
/dto/user.dto.go:
--------------------------------------------------------------------------------
1 | package dto
2 |
3 | type UpdateUserRequest struct {
4 | ID int64 `json:"id" form:"id"`
5 | Name string `json:"name" form:"name" binding:"required,min=1"`
6 | Email string `json:"email" form:"email" binding:"required,email"`
7 | }
8 |
--------------------------------------------------------------------------------
/entity/product.entity.go:
--------------------------------------------------------------------------------
1 | package entity
2 |
3 | type Product struct {
4 | ID int64 `gorm:"primary_key:auto_increment" json:"-"`
5 | Name string `gorm:"type:text" json:"-"`
6 | Price uint64 `gorm:"type:bigint" json:"-"`
7 | UserID int64 `gorm:"not null" json:"-"`
8 | User User `gorm:"foreignkey:UserID;constraint:onUpdate:CASCADE,onDelete:CASCADE" json:"-"`
9 | }
10 |
--------------------------------------------------------------------------------
/entity/user.entity.go:
--------------------------------------------------------------------------------
1 | package entity
2 |
3 | type User struct {
4 | ID int64 `gorm:"primary_key:auto_increment" json:"-"`
5 | Name string `gorm:"type:varchar(100)" json:"-"`
6 | Email string `gorm:"type:varchar(100);unique;" json:"-"`
7 | Password string `gorm:"type:varchar(100)" json:"-"`
8 | }
9 |
--------------------------------------------------------------------------------
/go.mod:
--------------------------------------------------------------------------------
1 | module github.com/ydhnwb/golang_heroku
2 |
3 | // +heroku goVersion go1.15
4 | go 1.15
5 |
6 | require (
7 | github.com/dgrijalva/jwt-go v3.2.0+incompatible
8 | github.com/gin-gonic/gin v1.7.1
9 | github.com/go-playground/validator v9.31.0+incompatible // indirect
10 | github.com/go-playground/validator/v10 v10.5.0 // indirect
11 | github.com/golang/protobuf v1.5.2 // indirect
12 | github.com/joho/godotenv v1.3.0
13 | github.com/json-iterator/go v1.1.10 // indirect
14 | github.com/leodido/go-urn v1.2.1 // indirect
15 | github.com/mashingan/smapping v0.1.6
16 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
17 | github.com/modern-go/reflect2 v1.0.1 // indirect
18 | github.com/ugorji/go v1.2.5 // indirect
19 | golang.org/x/crypto v0.0.0-20210415154028-4f45737414dc
20 | golang.org/x/sys v0.0.0-20210415045647-66c3f260301c // indirect
21 | golang.org/x/text v0.3.6 // indirect
22 | golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
23 | google.golang.org/genproto v0.0.0-20210416161957-9910b6c460de
24 | google.golang.org/protobuf v1.26.0
25 | gopkg.in/go-playground/validator.v9 v9.31.0
26 | gopkg.in/yaml.v2 v2.4.0 // indirect
27 | gorm.io/driver/postgres v1.0.8
28 | gorm.io/gorm v1.21.8
29 | )
30 |
--------------------------------------------------------------------------------
/go.sum:
--------------------------------------------------------------------------------
1 | cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
2 | github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
3 | github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
4 | github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
5 | github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
6 | github.com/cockroachdb/apd v1.1.0 h1:3LFP3629v+1aKXU5Q37mxmRxX/pIu1nijXydLShEq5I=
7 | github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ=
8 | github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
9 | github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
10 | github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
11 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
12 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
13 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
14 | github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
15 | github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
16 | github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
17 | github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
18 | github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
19 | github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
20 | github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
21 | github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
22 | github.com/gin-gonic/gin v1.7.1 h1:qC89GU3p8TvKWMAVhEpmpB2CIb1hnqt2UdKZaP93mS8=
23 | github.com/gin-gonic/gin v1.7.1/go.mod h1:jD2toBW3GZUr5UMcdrwQA10I7RuaFOl/SGeDjXkfUtY=
24 | github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A=
25 | github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
26 | github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q=
27 | github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8=
28 | github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no=
29 | github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA=
30 | github.com/go-playground/validator v9.31.0+incompatible h1:UA72EPEogEnq76ehGdEDp4Mit+3FDh548oRqwVgNsHA=
31 | github.com/go-playground/validator v9.31.0+incompatible/go.mod h1:yrEkQXlcI+PugkyDjY2bRrL/UBU4f3rvrgkN3V8JEig=
32 | github.com/go-playground/validator/v10 v10.4.1 h1:pH2c5ADXtd66mxoE0Zm9SUhxE20r7aM3F26W0hOn+GE=
33 | github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4=
34 | github.com/go-playground/validator/v10 v10.5.0 h1:X9rflw/KmpACwT8zdrm1upefpvdy6ur8d1kWyq6sg3E=
35 | github.com/go-playground/validator/v10 v10.5.0/go.mod h1:xm76BBt941f7yWdGnI2DVPFFg1UK3YY04qifoXU3lOk=
36 | github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
37 | github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
38 | github.com/gofrs/uuid v3.2.0+incompatible h1:y12jRkkFxsd7GpqdSZ+/KCs/fJbqpEXSGd4+jfEaewE=
39 | github.com/gofrs/uuid v3.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
40 | github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
41 | github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
42 | github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
43 | github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
44 | github.com/golang/protobuf v1.3.3 h1:gyjaxf+svBWX08ZjK86iN9geUJF0H6gp2IRKX6Nf6/I=
45 | github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
46 | github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
47 | github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
48 | github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
49 | github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
50 | github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
51 | github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
52 | github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
53 | github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
54 | github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
55 | github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
56 | github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
57 | github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
58 | github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
59 | github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
60 | github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
61 | github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
62 | github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
63 | github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
64 | github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
65 | github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
66 | github.com/jackc/chunkreader v1.0.0 h1:4s39bBR8ByfqH+DKm8rQA3E1LHZWB9XWcrz8fqaZbe0=
67 | github.com/jackc/chunkreader v1.0.0/go.mod h1:RT6O25fNZIuasFJRyZ4R/Y2BbhasbmZXF9QQ7T3kePo=
68 | github.com/jackc/chunkreader/v2 v2.0.0/go.mod h1:odVSm741yZoC3dpHEUXIqA9tQRhFrgOHwnPIn9lDKlk=
69 | github.com/jackc/chunkreader/v2 v2.0.1 h1:i+RDz65UE+mmpjTfyz0MoVTnzeYxroil2G82ki7MGG8=
70 | github.com/jackc/chunkreader/v2 v2.0.1/go.mod h1:odVSm741yZoC3dpHEUXIqA9tQRhFrgOHwnPIn9lDKlk=
71 | github.com/jackc/pgconn v0.0.0-20190420214824-7e0022ef6ba3/go.mod h1:jkELnwuX+w9qN5YIfX0fl88Ehu4XC3keFuOJJk9pcnA=
72 | github.com/jackc/pgconn v0.0.0-20190824142844-760dd75542eb/go.mod h1:lLjNuW/+OfW9/pnVKPazfWOgNfH2aPem8YQ7ilXGvJE=
73 | github.com/jackc/pgconn v0.0.0-20190831204454-2fabfa3c18b7/go.mod h1:ZJKsE/KZfsUgOEh9hBm+xYTstcNHg7UPMVJqRfQxq4s=
74 | github.com/jackc/pgconn v1.4.0/go.mod h1:Y2O3ZDF0q4mMacyWV3AstPJpeHXWGEetiFttmq5lahk=
75 | github.com/jackc/pgconn v1.5.0/go.mod h1:QeD3lBfpTFe8WUnPZWN5KY/mB8FGMIYRdd8P8Jr0fAI=
76 | github.com/jackc/pgconn v1.5.1-0.20200601181101-fa742c524853/go.mod h1:QeD3lBfpTFe8WUnPZWN5KY/mB8FGMIYRdd8P8Jr0fAI=
77 | github.com/jackc/pgconn v1.8.0 h1:FmjZ0rOyXTr1wfWs45i4a9vjnjWUAGpMuQLD9OSs+lw=
78 | github.com/jackc/pgconn v1.8.0/go.mod h1:1C2Pb36bGIP9QHGBYCjnyhqu7Rv3sGshaQUvmfGIB/o=
79 | github.com/jackc/pgio v1.0.0 h1:g12B9UwVnzGhueNavwioyEEpAmqMe1E/BN9ES+8ovkE=
80 | github.com/jackc/pgio v1.0.0/go.mod h1:oP+2QK2wFfUWgr+gxjoBH9KGBb31Eio69xUb0w5bYf8=
81 | github.com/jackc/pgmock v0.0.0-20190831213851-13a1b77aafa2 h1:JVX6jT/XfzNqIjye4717ITLaNwV9mWbJx0dLCpcRzdA=
82 | github.com/jackc/pgmock v0.0.0-20190831213851-13a1b77aafa2/go.mod h1:fGZlG77KXmcq05nJLRkk0+p82V8B8Dw8KN2/V9c/OAE=
83 | github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
84 | github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
85 | github.com/jackc/pgproto3 v1.1.0 h1:FYYE4yRw+AgI8wXIinMlNjBbp/UitDJwfj5LqqewP1A=
86 | github.com/jackc/pgproto3 v1.1.0/go.mod h1:eR5FA3leWg7p9aeAqi37XOTgTIbkABlvcPB3E5rlc78=
87 | github.com/jackc/pgproto3/v2 v2.0.0-alpha1.0.20190420180111-c116219b62db/go.mod h1:bhq50y+xrl9n5mRYyCBFKkpRVTLYJVWeCc+mEAI3yXA=
88 | github.com/jackc/pgproto3/v2 v2.0.0-alpha1.0.20190609003834-432c2951c711/go.mod h1:uH0AWtUmuShn0bcesswc4aBTWGvw0cAxIJp+6OB//Wg=
89 | github.com/jackc/pgproto3/v2 v2.0.0-rc3/go.mod h1:ryONWYqW6dqSg1Lw6vXNMXoBJhpzvWKnT95C46ckYeM=
90 | github.com/jackc/pgproto3/v2 v2.0.0-rc3.0.20190831210041-4c03ce451f29/go.mod h1:ryONWYqW6dqSg1Lw6vXNMXoBJhpzvWKnT95C46ckYeM=
91 | github.com/jackc/pgproto3/v2 v2.0.1/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA=
92 | github.com/jackc/pgproto3/v2 v2.0.6 h1:b1105ZGEMFe7aCvrT1Cca3VoVb4ZFMaFJLJcg/3zD+8=
93 | github.com/jackc/pgproto3/v2 v2.0.6/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA=
94 | github.com/jackc/pgservicefile v0.0.0-20200307190119-3430c5407db8/go.mod h1:vsD4gTJCa9TptPL8sPkXrLZ+hDuNrZCnj29CQpr4X1E=
95 | github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b h1:C8S2+VttkHFdOOCXJe+YGfa4vHYwlt4Zx+IVXQ97jYg=
96 | github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b/go.mod h1:vsD4gTJCa9TptPL8sPkXrLZ+hDuNrZCnj29CQpr4X1E=
97 | github.com/jackc/pgtype v0.0.0-20190421001408-4ed0de4755e0/go.mod h1:hdSHsc1V01CGwFsrv11mJRHWJ6aifDLfdV3aVjFF0zg=
98 | github.com/jackc/pgtype v0.0.0-20190824184912-ab885b375b90/go.mod h1:KcahbBH1nCMSo2DXpzsoWOAfFkdEtEJpPbVLq8eE+mc=
99 | github.com/jackc/pgtype v0.0.0-20190828014616-a8802b16cc59/go.mod h1:MWlu30kVJrUS8lot6TQqcg7mtthZ9T0EoIBFiJcmcyw=
100 | github.com/jackc/pgtype v1.2.0/go.mod h1:5m2OfMh1wTK7x+Fk952IDmI4nw3nPrvtQdM0ZT4WpC0=
101 | github.com/jackc/pgtype v1.3.1-0.20200510190516-8cd94a14c75a/go.mod h1:vaogEUkALtxZMCH411K+tKzNpwzCKU+AnPzBKZ+I+Po=
102 | github.com/jackc/pgtype v1.3.1-0.20200606141011-f6355165a91c/go.mod h1:cvk9Bgu/VzJ9/lxTO5R5sf80p0DiucVtN7ZxvaC4GmQ=
103 | github.com/jackc/pgtype v1.6.2 h1:b3pDeuhbbzBYcg5kwNmNDun4pFUD/0AAr1kLXZLeNt8=
104 | github.com/jackc/pgtype v1.6.2/go.mod h1:JCULISAZBFGrHaOXIIFiyfzW5VY0GRitRr8NeJsrdig=
105 | github.com/jackc/pgx/v4 v4.0.0-20190420224344-cc3461e65d96/go.mod h1:mdxmSJJuR08CZQyj1PVQBHy9XOp5p8/SHH6a0psbY9Y=
106 | github.com/jackc/pgx/v4 v4.0.0-20190421002000-1b8f0016e912/go.mod h1:no/Y67Jkk/9WuGR0JG/JseM9irFbnEPbuWV2EELPNuM=
107 | github.com/jackc/pgx/v4 v4.0.0-pre1.0.20190824185557-6972a5742186/go.mod h1:X+GQnOEnf1dqHGpw7JmHqHc1NxDoalibchSk9/RWuDc=
108 | github.com/jackc/pgx/v4 v4.5.0/go.mod h1:EpAKPLdnTorwmPUUsqrPxy5fphV18j9q3wrfRXgo+kA=
109 | github.com/jackc/pgx/v4 v4.6.1-0.20200510190926-94ba730bb1e9/go.mod h1:t3/cdRQl6fOLDxqtlyhe9UWgfIi9R8+8v8GKV5TRA/o=
110 | github.com/jackc/pgx/v4 v4.6.1-0.20200606145419-4e5062306904/go.mod h1:ZDaNWkt9sW1JMiNn0kdYBaLelIhw7Pg4qd+Vk6tw7Hg=
111 | github.com/jackc/pgx/v4 v4.10.1 h1:/6Q3ye4myIj6AaplUm+eRcz4OhK9HAvFf4ePsG40LJY=
112 | github.com/jackc/pgx/v4 v4.10.1/go.mod h1:QlrWebbs3kqEZPHCTGyxecvzG6tvIsYu+A5b1raylkA=
113 | github.com/jackc/puddle v0.0.0-20190413234325-e4ced69a3a2b/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
114 | github.com/jackc/puddle v0.0.0-20190608224051-11cab39313c9/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
115 | github.com/jackc/puddle v1.1.0/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
116 | github.com/jackc/puddle v1.1.1/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
117 | github.com/jackc/puddle v1.1.3/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
118 | github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
119 | github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
120 | github.com/jinzhu/now v1.1.1/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
121 | github.com/jinzhu/now v1.1.2 h1:eVKgfIdy9b6zbWBMgFpfDPoAMifwSZagU9HmEU6zgiI=
122 | github.com/jinzhu/now v1.1.2/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
123 | github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
124 | github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
125 | github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns=
126 | github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
127 | github.com/json-iterator/go v1.1.10 h1:Kz6Cvnvv2wGdaG/V8yMvfkmNiXq9Ya2KUv4rouJJr68=
128 | github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
129 | github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
130 | github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
131 | github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
132 | github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
133 | github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
134 | github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
135 | github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw=
136 | github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
137 | github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
138 | github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
139 | github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w=
140 | github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY=
141 | github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
142 | github.com/lib/pq v1.1.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
143 | github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
144 | github.com/lib/pq v1.3.0 h1:/qkRGz8zljWiDcFvgpwUpwIAPu3r07TDvs3Rws+o/pU=
145 | github.com/lib/pq v1.3.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
146 | github.com/mashingan/smapping v0.1.6 h1:6iCWWhx+g0dGcO4b+zP3DaqND/lCJFAdk547h+2JdWM=
147 | github.com/mashingan/smapping v0.1.6/go.mod h1:FjfiwFxGOuNxL/OT1WcrNAwTPx0YJeg5JiXwBB1nyig=
148 | github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ=
149 | github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
150 | github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
151 | github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
152 | github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
153 | github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
154 | github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ=
155 | github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
156 | github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
157 | github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
158 | github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
159 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
160 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
161 | github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg=
162 | github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
163 | github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI=
164 | github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
165 | github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
166 | github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
167 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
168 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
169 | github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
170 | github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
171 | github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ=
172 | github.com/rs/zerolog v1.13.0/go.mod h1:YbFCdg8HfsridGWAh22vktObvhZbQsZXe4/zB0OKkWU=
173 | github.com/rs/zerolog v1.15.0/go.mod h1:xYTKnLHcpfU2225ny5qZjxnj9NvkumZYjJHlAThCjNc=
174 | github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
175 | github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4=
176 | github.com/shopspring/decimal v0.0.0-20200227202807-02e2044944cc h1:jUIKcSPO9MoMJBbEoyE/RJoE8vz7Mb8AjvifMMwSyvY=
177 | github.com/shopspring/decimal v0.0.0-20200227202807-02e2044944cc/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
178 | github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
179 | github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
180 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
181 | github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
182 | github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
183 | github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
184 | github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
185 | github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
186 | github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
187 | github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
188 | github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
189 | github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo=
190 | github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
191 | github.com/ugorji/go v1.2.5 h1:NozRHfUeEta89taVkyfsDVSy2f7v89Frft4pjnWuGuc=
192 | github.com/ugorji/go v1.2.5/go.mod h1:gat2tIT8KJG8TVI8yv77nEO/KYT6dV7JE1gfUa8Xuls=
193 | github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs=
194 | github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
195 | github.com/ugorji/go/codec v1.2.5 h1:8WobZKAk18Msm2CothY2jnztY56YVY8kF1oQrj21iis=
196 | github.com/ugorji/go/codec v1.2.5/go.mod h1:QPxoTbPKSEAlAHPYt02++xp/en9B/wUdwFCz+hj5caA=
197 | github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
198 | github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q=
199 | go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
200 | go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
201 | go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
202 | go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
203 | go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU=
204 | go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA=
205 | go.uber.org/zap v1.9.1/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
206 | go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
207 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
208 | golang.org/x/crypto v0.0.0-20190411191339-88737f569e3a/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE=
209 | golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
210 | golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
211 | golang.org/x/crypto v0.0.0-20190911031432-227b76d455e7/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
212 | golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
213 | golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
214 | golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI=
215 | golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
216 | golang.org/x/crypto v0.0.0-20210415154028-4f45737414dc h1:+q90ECDSAQirdykUN6sPEiBXBsp8Csjcca8Oy7bgLTA=
217 | golang.org/x/crypto v0.0.0-20210415154028-4f45737414dc/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
218 | golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
219 | golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
220 | golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
221 | golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
222 | golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
223 | golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
224 | golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
225 | golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
226 | golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
227 | golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
228 | golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
229 | golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
230 | golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
231 | golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
232 | golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
233 | golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
234 | golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
235 | golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
236 | golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLdyRGr576XBO4/greRjx4P4O3yc=
237 | golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
238 | golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
239 | golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
240 | golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
241 | golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
242 | golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
243 | golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
244 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
245 | golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
246 | golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
247 | golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
248 | golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
249 | golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
250 | golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
251 | golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
252 | golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae h1:/WDfKMnPU+m5M4xB+6x4kaepxRw6jWvR5iDRdvjHgy8=
253 | golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
254 | golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
255 | golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
256 | golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
257 | golang.org/x/sys v0.0.0-20210315160823-c6e025ad8005/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
258 | golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
259 | golang.org/x/sys v0.0.0-20210415045647-66c3f260301c h1:6L+uOeS3OQt/f4eFHXZcTxeZrGCuz+CLElgEBjbcTA4=
260 | golang.org/x/sys v0.0.0-20210415045647-66c3f260301c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
261 | golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
262 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
263 | golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
264 | golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
265 | golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
266 | golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
267 | golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
268 | golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
269 | golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
270 | golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
271 | golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
272 | golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
273 | golang.org/x/tools v0.0.0-20190425163242-31fd60d6bfdc/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
274 | golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
275 | golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
276 | golang.org/x/tools v0.0.0-20190823170909-c4a336ef6a2f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
277 | golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
278 | golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
279 | golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
280 | golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
281 | golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
282 | golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
283 | golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
284 | golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
285 | golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
286 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
287 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
288 | golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
289 | golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
290 | google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
291 | google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
292 | google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
293 | google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
294 | google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
295 | google.golang.org/genproto v0.0.0-20210416161957-9910b6c460de h1:+nG/xknR+Gc5ByHOtK1dT0Pl3LYo8NLR+Jz3XeBeGEg=
296 | google.golang.org/genproto v0.0.0-20210416161957-9910b6c460de/go.mod h1:P3QM42oQyzQSnHPnZ/vqoCdDmzH28fzWByN9asMeM8A=
297 | google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
298 | google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
299 | google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
300 | google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
301 | google.golang.org/grpc v1.36.1/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU=
302 | google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
303 | google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
304 | google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
305 | google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
306 | google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
307 | google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
308 | google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
309 | google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
310 | google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
311 | google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
312 | google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk=
313 | google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
314 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
315 | gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
316 | gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
317 | gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
318 | gopkg.in/go-playground/validator.v9 v9.31.0 h1:bmXmP2RSNtFES+bn4uYuHT7iJFJv7Vj+an+ZQdDaD1M=
319 | gopkg.in/go-playground/validator.v9 v9.31.0/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWdVbfP1avr/N00E2vyQ=
320 | gopkg.in/inconshreveable/log15.v2 v2.0.0-20180818164646-67afb5ed74ec/go.mod h1:aPpfJ7XW+gOuirDoZ8gHhLh3kZ1B08FtV2bbmy7Jv3s=
321 | gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
322 | gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
323 | gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
324 | gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
325 | gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
326 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
327 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
328 | gorm.io/driver/mysql v1.0.5/go.mod h1:N1OIhHAIhx5SunkMGqWbGFVeh4yTNWKmMo1GOAsohLI=
329 | gorm.io/driver/postgres v1.0.8 h1:PAgM+PaHOSAeroTjHkCHCBIHHoBIf9RgPWGo8dF2DA8=
330 | gorm.io/driver/postgres v1.0.8/go.mod h1:4eOzrI1MUfm6ObJU/UcmbXyiHSs8jSwH95G5P5dxcAg=
331 | gorm.io/gorm v1.20.12/go.mod h1:0HFTzE/SqkGTzK6TlDPPQbAYCluiVvhzoA1+aVyzenw=
332 | gorm.io/gorm v1.21.3/go.mod h1:0HFTzE/SqkGTzK6TlDPPQbAYCluiVvhzoA1+aVyzenw=
333 | gorm.io/gorm v1.21.8 h1:2CEwZSzogdhsKPlJ9OvBKTdlWIpELXb6HbfLfMNhSYI=
334 | gorm.io/gorm v1.21.8/go.mod h1:F+OptMscr0P2F2qU97WT1WimdH9GaQPoDW7AYd5i2Y0=
335 | honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
336 | honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
337 | honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
338 |
--------------------------------------------------------------------------------
/handler/v1/auth.handler.go:
--------------------------------------------------------------------------------
1 | package v1
2 |
3 | import (
4 | "net/http"
5 | "strconv"
6 |
7 | "github.com/gin-gonic/gin"
8 | "github.com/ydhnwb/golang_heroku/common/obj"
9 | "github.com/ydhnwb/golang_heroku/common/response"
10 | "github.com/ydhnwb/golang_heroku/dto"
11 | "github.com/ydhnwb/golang_heroku/service"
12 | )
13 |
14 | type AuthHandler interface {
15 | Login(ctx *gin.Context)
16 | Register(ctx *gin.Context)
17 | }
18 |
19 | type authHandler struct {
20 | authService service.AuthService
21 | jwtService service.JWTService
22 | userService service.UserService
23 | }
24 |
25 | func NewAuthHandler(
26 | authService service.AuthService,
27 | jwtService service.JWTService,
28 | userService service.UserService,
29 | ) AuthHandler {
30 | return &authHandler{
31 | authService: authService,
32 | jwtService: jwtService,
33 | userService: userService,
34 | }
35 | }
36 |
37 | func (c *authHandler) Login(ctx *gin.Context) {
38 | var loginRequest dto.LoginRequest
39 | err := ctx.ShouldBind(&loginRequest)
40 |
41 | if err != nil {
42 | response := response.BuildErrorResponse("Failed to process request", err.Error(), obj.EmptyObj{})
43 | ctx.AbortWithStatusJSON(http.StatusBadRequest, response)
44 | return
45 | }
46 |
47 | err = c.authService.VerifyCredential(loginRequest.Email, loginRequest.Password)
48 | if err != nil {
49 | response := response.BuildErrorResponse("Failed to login", err.Error(), obj.EmptyObj{})
50 | ctx.AbortWithStatusJSON(http.StatusUnauthorized, response)
51 | return
52 | }
53 |
54 | user, _ := c.userService.FindUserByEmail(loginRequest.Email)
55 |
56 | token := c.jwtService.GenerateToken(strconv.FormatInt(user.ID, 10))
57 | user.Token = token
58 | response := response.BuildResponse(true, "OK!", user)
59 | ctx.JSON(http.StatusOK, response)
60 |
61 | }
62 |
63 | func (c *authHandler) Register(ctx *gin.Context) {
64 | var registerRequest dto.RegisterRequest
65 |
66 | err := ctx.ShouldBind(®isterRequest)
67 | if err != nil {
68 | response := response.BuildErrorResponse("Failed to process request", err.Error(), obj.EmptyObj{})
69 | ctx.AbortWithStatusJSON(http.StatusBadRequest, response)
70 | return
71 | }
72 |
73 | user, err := c.userService.CreateUser(registerRequest)
74 | if err != nil {
75 | response := response.BuildErrorResponse(err.Error(), err.Error(), obj.EmptyObj{})
76 | ctx.AbortWithStatusJSON(http.StatusUnprocessableEntity, response)
77 | return
78 | }
79 |
80 | token := c.jwtService.GenerateToken(strconv.FormatInt(user.ID, 10))
81 | user.Token = token
82 | response := response.BuildResponse(true, "OK!", user)
83 | ctx.JSON(http.StatusCreated, response)
84 |
85 | }
86 |
--------------------------------------------------------------------------------
/handler/v1/check.handler.go:
--------------------------------------------------------------------------------
1 | package v1
2 |
3 | import (
4 | "net/http"
5 |
6 | "github.com/gin-gonic/gin"
7 | )
8 |
9 | func Health(ctx *gin.Context) {
10 | response := map[string]string{
11 | "message": "ok!",
12 | }
13 | ctx.JSON(http.StatusOK, response)
14 | }
15 |
--------------------------------------------------------------------------------
/handler/v1/product.handler.go:
--------------------------------------------------------------------------------
1 | package v1
2 |
3 | import (
4 | "fmt"
5 | "net/http"
6 | "strconv"
7 |
8 | "github.com/dgrijalva/jwt-go"
9 | "github.com/gin-gonic/gin"
10 | "github.com/ydhnwb/golang_heroku/common/obj"
11 | "github.com/ydhnwb/golang_heroku/common/response"
12 | "github.com/ydhnwb/golang_heroku/dto"
13 | "github.com/ydhnwb/golang_heroku/service"
14 | )
15 |
16 | type ProductHandler interface {
17 | All(ctx *gin.Context)
18 | CreateProduct(ctx *gin.Context)
19 | UpdateProduct(ctx *gin.Context)
20 | DeleteProduct(ctx *gin.Context)
21 | FindOneProductByID(ctx *gin.Context)
22 | }
23 |
24 | type productHandler struct {
25 | productService service.ProductService
26 | jwtService service.JWTService
27 | }
28 |
29 | func NewProductHandler(productService service.ProductService, jwtService service.JWTService) ProductHandler {
30 | return &productHandler{
31 | productService: productService,
32 | jwtService: jwtService,
33 | }
34 | }
35 |
36 | func (c *productHandler) All(ctx *gin.Context) {
37 | authHeader := ctx.GetHeader("Authorization")
38 | token := c.jwtService.ValidateToken(authHeader, ctx)
39 | claims := token.Claims.(jwt.MapClaims)
40 | userID := fmt.Sprintf("%v", claims["user_id"])
41 |
42 | products, err := c.productService.All(userID)
43 | if err != nil {
44 | response := response.BuildErrorResponse("Failed to process request", err.Error(), obj.EmptyObj{})
45 | ctx.AbortWithStatusJSON(http.StatusBadRequest, response)
46 | return
47 | }
48 |
49 | response := response.BuildResponse(true, "OK!", products)
50 | ctx.JSON(http.StatusOK, response)
51 | }
52 |
53 | func (c *productHandler) CreateProduct(ctx *gin.Context) {
54 | var createProductReq dto.CreateProductRequest
55 | err := ctx.ShouldBind(&createProductReq)
56 |
57 | if err != nil {
58 | response := response.BuildErrorResponse("Failed to process request", err.Error(), obj.EmptyObj{})
59 | ctx.AbortWithStatusJSON(http.StatusBadRequest, response)
60 | return
61 | }
62 |
63 | authHeader := ctx.GetHeader("Authorization")
64 | token := c.jwtService.ValidateToken(authHeader, ctx)
65 | claims := token.Claims.(jwt.MapClaims)
66 | userID := fmt.Sprintf("%v", claims["user_id"])
67 |
68 | res, err := c.productService.CreateProduct(createProductReq, userID)
69 | if err != nil {
70 | response := response.BuildErrorResponse("Failed to process request", err.Error(), obj.EmptyObj{})
71 | ctx.AbortWithStatusJSON(http.StatusUnprocessableEntity, response)
72 | return
73 | }
74 |
75 | response := response.BuildResponse(true, "OK!", res)
76 | ctx.JSON(http.StatusCreated, response)
77 |
78 | }
79 |
80 | func (c *productHandler) FindOneProductByID(ctx *gin.Context) {
81 | id := ctx.Param("id")
82 |
83 | res, err := c.productService.FindOneProductByID(id)
84 | if err != nil {
85 | response := response.BuildErrorResponse("Failed to process request", err.Error(), obj.EmptyObj{})
86 | ctx.AbortWithStatusJSON(http.StatusBadRequest, response)
87 | return
88 | }
89 |
90 | response := response.BuildResponse(true, "OK!", res)
91 | ctx.JSON(http.StatusOK, response)
92 | }
93 |
94 | func (c *productHandler) DeleteProduct(ctx *gin.Context) {
95 | id := ctx.Param("id")
96 |
97 | authHeader := ctx.GetHeader("Authorization")
98 | token := c.jwtService.ValidateToken(authHeader, ctx)
99 | claims := token.Claims.(jwt.MapClaims)
100 | userID := fmt.Sprintf("%v", claims["user_id"])
101 |
102 | err := c.productService.DeleteProduct(id, userID)
103 | if err != nil {
104 | response := response.BuildErrorResponse("Failed to process request", err.Error(), obj.EmptyObj{})
105 | ctx.AbortWithStatusJSON(http.StatusBadRequest, response)
106 | return
107 | }
108 | response := response.BuildResponse(true, "OK!", obj.EmptyObj{})
109 | ctx.JSON(http.StatusOK, response)
110 | }
111 |
112 | func (c *productHandler) UpdateProduct(ctx *gin.Context) {
113 | updateProductRequest := dto.UpdateProductRequest{}
114 | err := ctx.ShouldBind(&updateProductRequest)
115 |
116 | if err != nil {
117 | response := response.BuildErrorResponse("Failed to process request", err.Error(), obj.EmptyObj{})
118 | ctx.AbortWithStatusJSON(http.StatusBadRequest, response)
119 | return
120 | }
121 |
122 | authHeader := ctx.GetHeader("Authorization")
123 | token := c.jwtService.ValidateToken(authHeader, ctx)
124 | claims := token.Claims.(jwt.MapClaims)
125 | userID := fmt.Sprintf("%v", claims["user_id"])
126 |
127 | id, _ := strconv.ParseInt(ctx.Param("id"), 0, 64)
128 | updateProductRequest.ID = id
129 | product, err := c.productService.UpdateProduct(updateProductRequest, userID)
130 | if err != nil {
131 | response := response.BuildErrorResponse("Failed to process request", err.Error(), obj.EmptyObj{})
132 | ctx.AbortWithStatusJSON(http.StatusUnprocessableEntity, response)
133 | return
134 | }
135 |
136 | response := response.BuildResponse(true, "OK!", product)
137 | ctx.JSON(http.StatusOK, response)
138 |
139 | }
140 |
--------------------------------------------------------------------------------
/handler/v1/user.handler.go:
--------------------------------------------------------------------------------
1 | package v1
2 |
3 | import (
4 | "fmt"
5 | "net/http"
6 | "strconv"
7 |
8 | "github.com/dgrijalva/jwt-go"
9 | "github.com/gin-gonic/gin"
10 | "github.com/ydhnwb/golang_heroku/common/obj"
11 | "github.com/ydhnwb/golang_heroku/common/response"
12 | "github.com/ydhnwb/golang_heroku/dto"
13 | "github.com/ydhnwb/golang_heroku/service"
14 | )
15 |
16 | type UserHandler interface {
17 | Profile(ctx *gin.Context)
18 | Update(ctx *gin.Context)
19 | }
20 |
21 | type userHandler struct {
22 | userService service.UserService
23 | jwtService service.JWTService
24 | }
25 |
26 | func NewUserHandler(
27 | userService service.UserService,
28 | jwtService service.JWTService,
29 | ) UserHandler {
30 | return &userHandler{
31 | userService: userService,
32 | jwtService: jwtService,
33 | }
34 | }
35 |
36 | func (c *userHandler) getUserIDByHeader(ctx *gin.Context) string {
37 | header := ctx.GetHeader("Authorization")
38 | token := c.jwtService.ValidateToken(header, ctx)
39 |
40 | if token == nil {
41 | response := response.BuildErrorResponse("Error", "Failed to validate token", obj.EmptyObj{})
42 | ctx.AbortWithStatusJSON(http.StatusUnauthorized, response)
43 | return ""
44 | }
45 |
46 | claims := token.Claims.(jwt.MapClaims)
47 | id := fmt.Sprintf("%v", claims["user_id"])
48 | return id
49 | }
50 |
51 | func (c *userHandler) Update(ctx *gin.Context) {
52 | var updateUserRequest dto.UpdateUserRequest
53 |
54 | err := ctx.ShouldBind(&updateUserRequest)
55 | if err != nil {
56 | response := response.BuildErrorResponse("Failed to process request", err.Error(), obj.EmptyObj{})
57 | ctx.AbortWithStatusJSON(http.StatusBadRequest, response)
58 | return
59 | }
60 |
61 | id := c.getUserIDByHeader(ctx)
62 |
63 | if id == "" {
64 | response := response.BuildErrorResponse("Error", "Failed to validate token", obj.EmptyObj{})
65 | ctx.AbortWithStatusJSON(http.StatusUnauthorized, response)
66 | return
67 | }
68 |
69 | _id, _ := strconv.ParseInt(id, 0, 64)
70 | updateUserRequest.ID = _id
71 | res, err := c.userService.UpdateUser(updateUserRequest)
72 |
73 | if err != nil {
74 | response := response.BuildErrorResponse("Error", err.Error(), obj.EmptyObj{})
75 | ctx.AbortWithStatusJSON(http.StatusUnauthorized, response)
76 | return
77 | }
78 |
79 | response := response.BuildResponse(true, "OK", res)
80 | ctx.JSON(http.StatusOK, response)
81 |
82 | }
83 |
84 | func (c *userHandler) Profile(ctx *gin.Context) {
85 | header := ctx.GetHeader("Authorization")
86 | token := c.jwtService.ValidateToken(header, ctx)
87 |
88 | if token == nil {
89 | response := response.BuildErrorResponse("Error", "Failed to validate token", obj.EmptyObj{})
90 | ctx.AbortWithStatusJSON(http.StatusUnauthorized, response)
91 | }
92 |
93 | claims := token.Claims.(jwt.MapClaims)
94 | id := fmt.Sprintf("%v", claims["user_id"])
95 | user, err := c.userService.FindUserByID(id)
96 |
97 | if err != nil {
98 | response := response.BuildErrorResponse("Error", err.Error(), obj.EmptyObj{})
99 | ctx.AbortWithStatusJSON(http.StatusBadRequest, response)
100 | }
101 |
102 | res := response.BuildResponse(true, "OK", user)
103 | ctx.JSON(http.StatusOK, res)
104 | }
105 |
--------------------------------------------------------------------------------
/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "github.com/gin-gonic/gin"
5 | "github.com/ydhnwb/golang_heroku/config"
6 | v1 "github.com/ydhnwb/golang_heroku/handler/v1"
7 | "github.com/ydhnwb/golang_heroku/middleware"
8 | "github.com/ydhnwb/golang_heroku/repo"
9 | "github.com/ydhnwb/golang_heroku/service"
10 | "gorm.io/gorm"
11 | )
12 |
13 | var (
14 | db *gorm.DB = config.SetupDatabaseConnection()
15 | userRepo repo.UserRepository = repo.NewUserRepo(db)
16 | productRepo repo.ProductRepository = repo.NewProductRepo(db)
17 | authService service.AuthService = service.NewAuthService(userRepo)
18 | jwtService service.JWTService = service.NewJWTService()
19 | userService service.UserService = service.NewUserService(userRepo)
20 | productService service.ProductService = service.NewProductService(productRepo)
21 | authHandler v1.AuthHandler = v1.NewAuthHandler(authService, jwtService, userService)
22 | userHandler v1.UserHandler = v1.NewUserHandler(userService, jwtService)
23 | productHandler v1.ProductHandler = v1.NewProductHandler(productService, jwtService)
24 | )
25 |
26 | func main() {
27 | defer config.CloseDatabaseConnection(db)
28 | server := gin.Default()
29 |
30 | authRoutes := server.Group("api/auth")
31 | {
32 | authRoutes.POST("/login", authHandler.Login)
33 | authRoutes.POST("/register", authHandler.Register)
34 | }
35 |
36 | userRoutes := server.Group("api/user", middleware.AuthorizeJWT(jwtService))
37 | {
38 | userRoutes.GET("/profile", userHandler.Profile)
39 | userRoutes.PUT("/profile", userHandler.Update)
40 | }
41 |
42 | productRoutes := server.Group("api/product", middleware.AuthorizeJWT(jwtService))
43 | {
44 | productRoutes.GET("/", productHandler.All)
45 | productRoutes.POST("/", productHandler.CreateProduct)
46 | productRoutes.GET("/:id", productHandler.FindOneProductByID)
47 | productRoutes.PUT("/:id", productHandler.UpdateProduct)
48 | productRoutes.DELETE("/:id", productHandler.DeleteProduct)
49 | }
50 |
51 | checkRoutes := server.Group("api/check")
52 | {
53 | checkRoutes.GET("health", v1.Health)
54 | }
55 |
56 | server.Run()
57 | }
58 |
--------------------------------------------------------------------------------
/middleware/auth.middleware.go:
--------------------------------------------------------------------------------
1 | package middleware
2 |
3 | import (
4 | "log"
5 | "net/http"
6 |
7 | "github.com/dgrijalva/jwt-go"
8 | "github.com/gin-gonic/gin"
9 | "github.com/ydhnwb/golang_heroku/common/response"
10 | "github.com/ydhnwb/golang_heroku/service"
11 | )
12 |
13 | //AuthorizeJWT validates the token user given, return 401 if not valid
14 | func AuthorizeJWT(jwtService service.JWTService) gin.HandlerFunc {
15 | return func(c *gin.Context) {
16 | authHeader := c.GetHeader("Authorization")
17 | if authHeader == "" {
18 | response := response.BuildErrorResponse("Failed to process request", "No token provided", nil)
19 | c.AbortWithStatusJSON(http.StatusBadRequest, response)
20 | return
21 | }
22 |
23 | token := jwtService.ValidateToken(authHeader, c)
24 | if token.Valid {
25 | claims := token.Claims.(jwt.MapClaims)
26 | log.Println("Claim[user_id]: ", claims["user_id"])
27 | log.Println("Claim[issuer] :", claims["issuer"])
28 | } else {
29 | response := response.BuildErrorResponse("Error", "Your token is not valid", nil)
30 | c.AbortWithStatusJSON(http.StatusUnauthorized, response)
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/repo/product.repo.go:
--------------------------------------------------------------------------------
1 | package repo
2 |
3 | import (
4 | "github.com/ydhnwb/golang_heroku/entity"
5 | "gorm.io/gorm"
6 | )
7 |
8 | type ProductRepository interface {
9 | All(userID string) ([]entity.Product, error)
10 | InsertProduct(product entity.Product) (entity.Product, error)
11 | UpdateProduct(product entity.Product) (entity.Product, error)
12 | DeleteProduct(productID string) error
13 | FindOneProductByID(ID string) (entity.Product, error)
14 | FindAllProduct(userID string) ([]entity.Product, error)
15 | }
16 |
17 | type productRepo struct {
18 | connection *gorm.DB
19 | }
20 |
21 | func NewProductRepo(connection *gorm.DB) ProductRepository {
22 | return &productRepo{
23 | connection: connection,
24 | }
25 | }
26 |
27 | func (c *productRepo) All(userID string) ([]entity.Product, error) {
28 | products := []entity.Product{}
29 | c.connection.Preload("User").Where("user_id = ?", userID).Find(&products)
30 | return products, nil
31 | }
32 |
33 | func (c *productRepo) InsertProduct(product entity.Product) (entity.Product, error) {
34 | c.connection.Save(&product)
35 | c.connection.Preload("User").Find(&product)
36 | return product, nil
37 | }
38 |
39 | func (c *productRepo) UpdateProduct(product entity.Product) (entity.Product, error) {
40 | c.connection.Save(&product)
41 | c.connection.Preload("User").Find(&product)
42 | return product, nil
43 | }
44 |
45 | func (c *productRepo) FindOneProductByID(productID string) (entity.Product, error) {
46 | var product entity.Product
47 | res := c.connection.Preload("User").Where("id = ?", productID).Take(&product)
48 | if res.Error != nil {
49 | return product, res.Error
50 | }
51 | return product, nil
52 | }
53 |
54 | func (c *productRepo) FindAllProduct(userID string) ([]entity.Product, error) {
55 | products := []entity.Product{}
56 | c.connection.Where("user_id = ?", userID).Find(&products)
57 | return products, nil
58 | }
59 |
60 | func (c *productRepo) DeleteProduct(productID string) error {
61 | var product entity.Product
62 | res := c.connection.Preload("User").Where("id = ?", productID).Take(&product)
63 | if res.Error != nil {
64 | return res.Error
65 | }
66 | c.connection.Delete(&product)
67 | return nil
68 | }
69 |
--------------------------------------------------------------------------------
/repo/user.repo.go:
--------------------------------------------------------------------------------
1 | package repo
2 |
3 | import (
4 | "log"
5 |
6 | "github.com/ydhnwb/golang_heroku/entity"
7 | "golang.org/x/crypto/bcrypt"
8 | "gorm.io/gorm"
9 | )
10 |
11 | type UserRepository interface {
12 | InsertUser(user entity.User) (entity.User, error)
13 | UpdateUser(user entity.User) (entity.User, error)
14 | FindByEmail(email string) (entity.User, error)
15 | FindByUserID(userID string) (entity.User, error)
16 | }
17 |
18 | type userRepo struct {
19 | connection *gorm.DB
20 | }
21 |
22 | func NewUserRepo(connection *gorm.DB) UserRepository {
23 | return &userRepo{
24 | connection: connection,
25 | }
26 | }
27 |
28 | func (c *userRepo) InsertUser(user entity.User) (entity.User, error) {
29 | user.Password = hashAndSalt([]byte(user.Password))
30 | c.connection.Save(&user)
31 | return user, nil
32 | }
33 |
34 | func (c *userRepo) UpdateUser(user entity.User) (entity.User, error) {
35 | if user.Password != "" {
36 | user.Password = hashAndSalt([]byte(user.Password))
37 | } else {
38 | var tempUser entity.User
39 | c.connection.Find(&tempUser, user.ID)
40 | user.Password = tempUser.Password
41 | }
42 |
43 | c.connection.Save(&user)
44 | return user, nil
45 | }
46 |
47 | func (c *userRepo) FindByEmail(email string) (entity.User, error) {
48 | var user entity.User
49 | res := c.connection.Where("email = ?", email).Take(&user)
50 | if res.Error != nil {
51 | return user, res.Error
52 | }
53 | return user, nil
54 | }
55 |
56 | func (c *userRepo) FindByUserID(userID string) (entity.User, error) {
57 | var user entity.User
58 | res := c.connection.Where("id = ?", userID).Take(&user)
59 | if res.Error != nil {
60 | return user, res.Error
61 | }
62 | return user, nil
63 | }
64 |
65 | func hashAndSalt(pwd []byte) string {
66 | hash, err := bcrypt.GenerateFromPassword(pwd, bcrypt.MinCost)
67 | if err != nil {
68 | log.Println(err)
69 | panic("Failed to hash a password")
70 | }
71 | return string(hash)
72 | }
73 |
--------------------------------------------------------------------------------
/service/auth.service.go:
--------------------------------------------------------------------------------
1 | package service
2 |
3 | import (
4 | "errors"
5 | "log"
6 |
7 | "github.com/ydhnwb/golang_heroku/repo"
8 | "golang.org/x/crypto/bcrypt"
9 | )
10 |
11 | type AuthService interface {
12 | VerifyCredential(email string, password string) error
13 | // CreateUser(user dto.) entity.User
14 | }
15 |
16 | type authService struct {
17 | userRepo repo.UserRepository
18 | }
19 |
20 | func NewAuthService(userRepo repo.UserRepository) AuthService {
21 | return &authService{
22 | userRepo: userRepo,
23 | }
24 | }
25 |
26 | func (c *authService) VerifyCredential(email string, password string) error {
27 | user, err := c.userRepo.FindByEmail(email)
28 | if err != nil {
29 | println("hehe")
30 | println(err.Error())
31 | return err
32 | }
33 |
34 | isValidPassword := comparePassword(user.Password, []byte(password))
35 | if !isValidPassword {
36 | return errors.New("failed to login. check your credential")
37 | }
38 |
39 | return nil
40 |
41 | }
42 |
43 | func comparePassword(hashedPwd string, plainPassword []byte) bool {
44 | byteHash := []byte(hashedPwd)
45 | err := bcrypt.CompareHashAndPassword(byteHash, plainPassword)
46 | if err != nil {
47 | log.Println(err)
48 | return false
49 | }
50 | return true
51 | }
52 |
--------------------------------------------------------------------------------
/service/jwt.service.go:
--------------------------------------------------------------------------------
1 | package service
2 |
3 | import (
4 | "fmt"
5 | "os"
6 | "time"
7 |
8 | "github.com/dgrijalva/jwt-go"
9 | "github.com/gin-gonic/gin"
10 | )
11 |
12 | //JWTService is a contract of what jwtService can do
13 | type JWTService interface {
14 | GenerateToken(userID string) string
15 | ValidateToken(token string, ctx *gin.Context) *jwt.Token
16 | }
17 |
18 | type jwtCustomClaim struct {
19 | UserID string `json:"user_id"`
20 | jwt.StandardClaims
21 | }
22 |
23 | type jwtService struct {
24 | secretKey string
25 | issuer string
26 | }
27 |
28 | //NewJWTService method is creates a new instance of JWTService
29 | func NewJWTService() JWTService {
30 | return &jwtService{
31 | issuer: "admin",
32 | secretKey: getSecretKey(),
33 | }
34 | }
35 |
36 | func getSecretKey() string {
37 | secretKey := os.Getenv("JWT_SECRET")
38 | if secretKey != "" {
39 | secretKey = "system"
40 | }
41 | return secretKey
42 | }
43 |
44 | func (j *jwtService) GenerateToken(UserID string) string {
45 | claims := &jwtCustomClaim{
46 | UserID,
47 | jwt.StandardClaims{
48 | ExpiresAt: time.Now().AddDate(1, 0, 0).Unix(),
49 | Issuer: j.issuer,
50 | IssuedAt: time.Now().Unix(),
51 | },
52 | }
53 | token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
54 | t, err := token.SignedString([]byte(j.secretKey))
55 | if err != nil {
56 | panic(err)
57 | }
58 | return t
59 | }
60 |
61 | func (j *jwtService) ValidateToken(token string, ctx *gin.Context) *jwt.Token {
62 | t, err := jwt.Parse(token, func(t_ *jwt.Token) (interface{}, error) {
63 | if _, ok := t_.Method.(*jwt.SigningMethodHMAC); !ok {
64 | return nil, fmt.Errorf("Unexpected signing method %v", t_.Header["alg"])
65 | }
66 | return []byte(j.secretKey), nil
67 | })
68 |
69 | if err != nil {
70 | return nil
71 | }
72 |
73 | return t
74 |
75 | }
76 |
--------------------------------------------------------------------------------
/service/product.service.go:
--------------------------------------------------------------------------------
1 | package service
2 |
3 | import (
4 | "errors"
5 | "fmt"
6 | "log"
7 | "strconv"
8 |
9 | "github.com/mashingan/smapping"
10 | "github.com/ydhnwb/golang_heroku/dto"
11 | "github.com/ydhnwb/golang_heroku/entity"
12 | "github.com/ydhnwb/golang_heroku/repo"
13 |
14 | _product "github.com/ydhnwb/golang_heroku/service/product"
15 | )
16 |
17 | type ProductService interface {
18 | All(userID string) (*[]_product.ProductResponse, error)
19 | CreateProduct(productRequest dto.CreateProductRequest, userID string) (*_product.ProductResponse, error)
20 | UpdateProduct(updateProductRequest dto.UpdateProductRequest, userID string) (*_product.ProductResponse, error)
21 | FindOneProductByID(productID string) (*_product.ProductResponse, error)
22 | DeleteProduct(productID string, userID string) error
23 | }
24 |
25 | type productService struct {
26 | productRepo repo.ProductRepository
27 | }
28 |
29 | func NewProductService(productRepo repo.ProductRepository) ProductService {
30 | return &productService{
31 | productRepo: productRepo,
32 | }
33 | }
34 |
35 | func (c *productService) All(userID string) (*[]_product.ProductResponse, error) {
36 | products, err := c.productRepo.All(userID)
37 | if err != nil {
38 | return nil, err
39 | }
40 |
41 | prods := _product.NewProductArrayResponse(products)
42 | return &prods, nil
43 | }
44 |
45 | func (c *productService) CreateProduct(productRequest dto.CreateProductRequest, userID string) (*_product.ProductResponse, error) {
46 | product := entity.Product{}
47 | err := smapping.FillStruct(&product, smapping.MapFields(&productRequest))
48 |
49 | if err != nil {
50 | log.Fatalf("Failed map %v", err)
51 | return nil, err
52 | }
53 |
54 | id, _ := strconv.ParseInt(userID, 0, 64)
55 | product.UserID = id
56 | p, err := c.productRepo.InsertProduct(product)
57 | if err != nil {
58 | return nil, err
59 | }
60 |
61 | res := _product.NewProductResponse(p)
62 | return &res, nil
63 | }
64 |
65 | func (c *productService) FindOneProductByID(productID string) (*_product.ProductResponse, error) {
66 | product, err := c.productRepo.FindOneProductByID(productID)
67 |
68 | if err != nil {
69 | return nil, err
70 | }
71 |
72 | res := _product.NewProductResponse(product)
73 | return &res, nil
74 | }
75 |
76 | func (c *productService) UpdateProduct(updateProductRequest dto.UpdateProductRequest, userID string) (*_product.ProductResponse, error) {
77 | product, err := c.productRepo.FindOneProductByID(fmt.Sprintf("%d", updateProductRequest.ID))
78 | if err != nil {
79 | return nil, err
80 | }
81 |
82 | uid, _ := strconv.ParseInt(userID, 0, 64)
83 | if product.UserID != uid {
84 | return nil, errors.New("produk ini bukan milik anda")
85 | }
86 |
87 | product = entity.Product{}
88 | err = smapping.FillStruct(&product, smapping.MapFields(&updateProductRequest))
89 |
90 | if err != nil {
91 | return nil, err
92 | }
93 |
94 | product.UserID = uid
95 | product, err = c.productRepo.UpdateProduct(product)
96 |
97 | if err != nil {
98 | return nil, err
99 | }
100 |
101 | res := _product.NewProductResponse(product)
102 | return &res, nil
103 | }
104 |
105 | func (c *productService) DeleteProduct(productID string, userID string) error {
106 | product, err := c.productRepo.FindOneProductByID(productID)
107 | if err != nil {
108 | return err
109 | }
110 |
111 | if fmt.Sprintf("%d", product.UserID) != userID {
112 | return errors.New("produk ini bukan milik anda")
113 | }
114 |
115 | c.productRepo.DeleteProduct(productID)
116 | return nil
117 |
118 | }
119 |
--------------------------------------------------------------------------------
/service/product/product.response.go:
--------------------------------------------------------------------------------
1 | package _product
2 |
3 | import (
4 | "github.com/ydhnwb/golang_heroku/entity"
5 | _user "github.com/ydhnwb/golang_heroku/service/user"
6 | )
7 |
8 | type ProductResponse struct {
9 | ID int64 `json:"id"`
10 | ProductName string `json:"product_name"`
11 | Price uint64 `json:"price"`
12 | User _user.UserResponse `json:"user,omitempty"`
13 | }
14 |
15 | func NewProductResponse(product entity.Product) ProductResponse {
16 | return ProductResponse{
17 | ID: product.ID,
18 | ProductName: product.Name,
19 | Price: product.Price,
20 | User: _user.NewUserResponse(product.User),
21 | }
22 | }
23 |
24 | func NewProductArrayResponse(products []entity.Product) []ProductResponse {
25 | productRes := []ProductResponse{}
26 | for _, v := range products {
27 | p := ProductResponse{
28 | ID: v.ID,
29 | ProductName: v.Name,
30 | Price: v.Price,
31 | User: _user.NewUserResponse(v.User),
32 | }
33 | productRes = append(productRes, p)
34 | }
35 | return productRes
36 | }
37 |
--------------------------------------------------------------------------------
/service/user.service.go:
--------------------------------------------------------------------------------
1 | package service
2 |
3 | import (
4 | "errors"
5 | "log"
6 |
7 | "github.com/mashingan/smapping"
8 | "github.com/ydhnwb/golang_heroku/dto"
9 | "github.com/ydhnwb/golang_heroku/entity"
10 | "github.com/ydhnwb/golang_heroku/repo"
11 | _user "github.com/ydhnwb/golang_heroku/service/user"
12 | "gorm.io/gorm"
13 | )
14 |
15 | type UserService interface {
16 | CreateUser(registerRequest dto.RegisterRequest) (*_user.UserResponse, error)
17 | UpdateUser(updateUserRequest dto.UpdateUserRequest) (*_user.UserResponse, error)
18 | FindUserByEmail(email string) (*_user.UserResponse, error)
19 | FindUserByID(userID string) (*_user.UserResponse, error)
20 | }
21 |
22 | type userService struct {
23 | userRepo repo.UserRepository
24 | }
25 |
26 | func NewUserService(userRepo repo.UserRepository) UserService {
27 | return &userService{
28 | userRepo: userRepo,
29 | }
30 | }
31 |
32 | func (c *userService) UpdateUser(updateUserRequest dto.UpdateUserRequest) (*_user.UserResponse, error) {
33 | user := entity.User{}
34 | err := smapping.FillStruct(&user, smapping.MapFields(&updateUserRequest))
35 |
36 | if err != nil {
37 | return nil, err
38 | }
39 |
40 | user, err = c.userRepo.UpdateUser(user)
41 | if err != nil {
42 | return nil, err
43 | }
44 |
45 | res := _user.NewUserResponse(user)
46 | return &res, nil
47 |
48 | }
49 |
50 | func (c *userService) CreateUser(registerRequest dto.RegisterRequest) (*_user.UserResponse, error) {
51 | user, err := c.userRepo.FindByEmail(registerRequest.Email)
52 |
53 | if err == nil {
54 | return nil, errors.New("user already exists")
55 | }
56 |
57 | if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
58 | return nil, err
59 | }
60 |
61 | err = smapping.FillStruct(&user, smapping.MapFields(®isterRequest))
62 |
63 | if err != nil {
64 | log.Fatalf("Failed map %v", err)
65 | return nil, err
66 | }
67 |
68 | user, _ = c.userRepo.InsertUser(user)
69 | res := _user.NewUserResponse(user)
70 | return &res, nil
71 |
72 | }
73 |
74 | func (c *userService) FindUserByEmail(email string) (*_user.UserResponse, error) {
75 | user, err := c.userRepo.FindByEmail(email)
76 |
77 | if err != nil {
78 | return nil, err
79 | }
80 |
81 | userResponse := _user.NewUserResponse(user)
82 | return &userResponse, nil
83 | }
84 |
85 | func (c *userService) FindUserByID(userID string) (*_user.UserResponse, error) {
86 | user, err := c.userRepo.FindByUserID(userID)
87 |
88 | if err != nil {
89 | return nil, err
90 | }
91 |
92 | userResponse := _user.UserResponse{}
93 | err = smapping.FillStruct(&userResponse, smapping.MapFields(&user))
94 | if err != nil {
95 | return nil, err
96 | }
97 | return &userResponse, nil
98 | }
99 |
--------------------------------------------------------------------------------
/service/user/user.response.go:
--------------------------------------------------------------------------------
1 | package _user
2 |
3 | import "github.com/ydhnwb/golang_heroku/entity"
4 |
5 | type UserResponse struct {
6 | ID int64 `json:"id"`
7 | Name string `json:"name"`
8 | Email string `json:"email"`
9 | Token string `json:"token,omitempty"`
10 | }
11 |
12 | func NewUserResponse(user entity.User) UserResponse {
13 | return UserResponse{
14 | ID: user.ID,
15 | Email: user.Email,
16 | Name: user.Name,
17 | }
18 | }
19 |
--------------------------------------------------------------------------------