Skip to content

Commit 245f3c8

Browse files
committed
⚡ Add logger
1 parent ebcf562 commit 245f3c8

File tree

12 files changed

+181
-36
lines changed

12 files changed

+181
-36
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
.idea
2-
.env
2+
.env
3+
cmd/todo-app/go_build_github_com_nhassl3_todo_app_cmd_todo_app
4+
commands_for_database.txt

cmd/todo-app/main.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"github.com/joho/godotenv"
66
"github.com/nhassl3/todo-app/pkg/config"
77
"github.com/nhassl3/todo-app/pkg/http-server/handlers"
8-
"github.com/nhassl3/todo-app/pkg/lib/logger/handlers/slogpretty"
8+
"github.com/nhassl3/todo-app/pkg/logger/handlers/slogpretty"
99
"github.com/nhassl3/todo-app/pkg/repository"
1010
"github.com/nhassl3/todo-app/pkg/service"
1111
"log/slog"
@@ -22,7 +22,7 @@ const (
2222

2323
func main() {
2424
// load dot environment
25-
if err := godotenv.Load(); err != nil {
25+
if err := godotenv.Load("../../.env"); err != nil {
2626
slog.Error("error loading .env variables", slog.String("error", err.Error()))
2727
}
2828

@@ -41,11 +41,12 @@ func main() {
4141
os.Exit(1)
4242
}
4343

44-
// http server
44+
// set up the repository, service and handlers
4545
repos := repository.NewRepository(db)
4646
services := service.NewService(repos)
47-
handler := handlers.NewMainHandler(services, log)
47+
handler := handlers.NewHandler(services, log)
4848

49+
// set up http server on localhost:8082
4950
server := new(Server)
5051
go func() {
5152
if err := server.Run(cfg, handler.InitRoutes()); err != nil {

go.mod

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,39 @@ module github.com/nhassl3/todo-app
22

33
go 1.22.2
44

5+
require (
6+
github.com/dgrijalva/jwt-go v3.2.0+incompatible
7+
github.com/fatih/color v1.18.0
8+
github.com/gin-gonic/gin v1.10.0
9+
github.com/go-chi/chi v1.5.5
10+
github.com/ilyakaznacheev/cleanenv v1.5.0
11+
github.com/jmoiron/sqlx v1.4.0
12+
github.com/joho/godotenv v1.5.1
13+
github.com/lib/pq v1.10.9
14+
github.com/samber/slog-gin v1.13.6
15+
)
16+
517
require (
618
github.com/BurntSushi/toml v1.4.0 // indirect
7-
github.com/brianvoe/gofakeit/v7 v7.1.2 // indirect
819
github.com/bytedance/sonic v1.12.4 // indirect
920
github.com/bytedance/sonic/loader v0.2.1 // indirect
1021
github.com/cloudwego/base64x v0.1.4 // indirect
1122
github.com/cloudwego/iasm v0.2.0 // indirect
12-
github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect
13-
github.com/fatih/color v1.18.0 // indirect
1423
github.com/gabriel-vasile/mimetype v1.4.6 // indirect
1524
github.com/gin-contrib/sse v0.1.0 // indirect
16-
github.com/gin-gonic/gin v1.10.0 // indirect
17-
github.com/go-chi/chi v1.5.5 // indirect
1825
github.com/go-playground/locales v0.14.1 // indirect
1926
github.com/go-playground/universal-translator v0.18.1 // indirect
2027
github.com/go-playground/validator/v10 v10.22.1 // indirect
2128
github.com/goccy/go-json v0.10.3 // indirect
2229
github.com/google/uuid v1.6.0 // indirect
23-
github.com/ilyakaznacheev/cleanenv v1.5.0 // indirect
24-
github.com/jmoiron/sqlx v1.4.0 // indirect
25-
github.com/joho/godotenv v1.5.1 // indirect
2630
github.com/json-iterator/go v1.1.12 // indirect
2731
github.com/klauspost/cpuid/v2 v2.2.9 // indirect
2832
github.com/leodido/go-urn v1.4.0 // indirect
29-
github.com/lib/pq v1.10.9 // indirect
3033
github.com/mattn/go-colorable v0.1.13 // indirect
3134
github.com/mattn/go-isatty v0.0.20 // indirect
3235
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
3336
github.com/modern-go/reflect2 v1.0.2 // indirect
3437
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
35-
github.com/samber/slog-gin v1.13.6 // indirect
3638
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
3739
github.com/ugorji/go/codec v1.2.12 // indirect
3840
go.opentelemetry.io/otel v1.29.0 // indirect

go.sum

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1+
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
12
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
23
github.com/BurntSushi/toml v1.2.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
34
github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0=
45
github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
5-
github.com/brianvoe/gofakeit/v7 v7.1.2 h1:vSKaVScNhWVpf1rlyEKSvO8zKZfuDtGqoIHT//iNNb8=
6-
github.com/brianvoe/gofakeit/v7 v7.1.2/go.mod h1:QXuPeBw164PJCzCUZVmgpgHJ3Llj49jSLVkKPMtxtxA=
76
github.com/bytedance/sonic v1.12.4 h1:9Csb3c9ZJhfUWeMtpCDCq6BUoH5ogfDFLUgQ/jG+R0k=
87
github.com/bytedance/sonic v1.12.4/go.mod h1:B8Gt/XvtZ3Fqj+iSKMypzymZxw/FVwgIGKzMzT9r/rk=
98
github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
@@ -14,6 +13,7 @@ github.com/cloudwego/base64x v0.1.4/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJ
1413
github.com/cloudwego/iasm v0.2.0 h1:1KNIy1I1H9hNNFEEH3DVnI4UujN+1zjpuk6gwHLTssg=
1514
github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY=
1615
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
16+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
1717
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1818
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
1919
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
@@ -27,15 +27,20 @@ github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU=
2727
github.com/gin-gonic/gin v1.10.0/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y=
2828
github.com/go-chi/chi v1.5.5 h1:vOB/HbEMt9QqBqErz07QehcOKHaWFtuj87tTDVz2qXE=
2929
github.com/go-chi/chi v1.5.5/go.mod h1:C9JqLr3tIYjDOZpzn+BCuxY8z8vmca43EeMgyZt7irw=
30+
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
31+
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
3032
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
3133
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
3234
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
3335
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
3436
github.com/go-playground/validator/v10 v10.22.1 h1:40JcKH+bBNGFczGuoBYgX4I6m/i27HYW8P9FDk5PbgA=
3537
github.com/go-playground/validator/v10 v10.22.1/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
38+
github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y=
3639
github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg=
3740
github.com/goccy/go-json v0.10.3 h1:KZ5WoDbxAIgm2HNbYckL0se1fHD6rz5j4ywS6ebzDqA=
3841
github.com/goccy/go-json v0.10.3/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
42+
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
43+
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
3944
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
4045
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
4146
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
@@ -51,6 +56,10 @@ github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa02
5156
github.com/klauspost/cpuid/v2 v2.2.9 h1:66ze0taIn2H33fBvCkXuv9BmCwDfafmiIVpKV9kKGuY=
5257
github.com/klauspost/cpuid/v2 v2.2.9/go.mod h1:rqkxqrZ1EhYM9G+hXH7YdowN5R5RGN6NK4QwQ3WMXF8=
5358
github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M=
59+
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
60+
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
61+
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
62+
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
5463
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
5564
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
5665
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
@@ -60,6 +69,7 @@ github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovk
6069
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
6170
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
6271
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
72+
github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU=
6373
github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
6474
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
6575
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
@@ -68,6 +78,7 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G
6878
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
6979
github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M=
7080
github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc=
81+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
7182
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
7283
github.com/samber/slog-gin v1.13.6 h1:clWpgtdL/3KM1eGkUMUHTLNM1fG4nA3bHC1Pt7v0z44=
7384
github.com/samber/slog-gin v1.13.6/go.mod h1:iicbXYT1DozbzsbLfpRdXkAal3zmzIjayQCV5YR+A6M=
@@ -79,6 +90,7 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
7990
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
8091
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
8192
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
93+
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
8294
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
8395
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
8496
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
@@ -96,19 +108,18 @@ golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4=
96108
golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU=
97109
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
98110
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
99-
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
100-
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
101111
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
102112
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
103113
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
104114
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
105115
google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA=
106116
google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
107117
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
118+
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
119+
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
108120
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
109121
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
110122
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
111123
nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50=
112124
olympos.io/encoding/edn v0.0.0-20201019073823-d3554ca0b0a3 h1:slmdOY3vp8a7KQbHkL+FLbvbkgMqmXojpFUO/jENuqQ=
113125
olympos.io/encoding/edn v0.0.0-20201019073823-d3554ca0b0a3/go.mod h1:oVgVk4OWVDi43qWBEyGhXgYxt7+ED4iYNpTngSLX2Iw=
114-
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=

pkg/http-server/handlers/auth.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"net/http"
88
)
99

10-
func (h *MainHandler) signUp(c *gin.Context) {
10+
func (h *Handler) signUp(c *gin.Context) {
1111
var input entity.User
1212

1313
if err := c.BindJSON(&input); err != nil {
@@ -38,7 +38,7 @@ type signInInput struct {
3838
Password string `json:"password" binding:"required"`
3939
}
4040

41-
func (h *MainHandler) signIn(c *gin.Context) {
41+
func (h *Handler) signIn(c *gin.Context) {
4242
var input signInInput
4343

4444
if err := c.BindJSON(&input); err != nil {

pkg/http-server/handlers/handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ type Handler struct {
1212
logger *slog.Logger
1313
}
1414

15-
func NewMainHandler(services *service.Service, logger *slog.Logger) *Handler {
15+
func NewHandler(services *service.Service, logger *slog.Logger) *Handler {
1616
return &Handler{services: services, logger: logger}
1717
}
1818

pkg/http-server/handlers/item.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@ package handlers
22

33
import "github.com/gin-gonic/gin"
44

5-
func (h *MainHandler) createItem(c *gin.Context) {
5+
func (h *Handler) createItem(c *gin.Context) {
66

77
}
88

9-
func (h *MainHandler) getAllItems(c *gin.Context) {
9+
func (h *Handler) getAllItems(c *gin.Context) {
1010

1111
}
1212

13-
func (h *MainHandler) getItemById(c *gin.Context) {
13+
func (h *Handler) getItemById(c *gin.Context) {
1414

1515
}
1616

17-
func (h *MainHandler) updateItem(c *gin.Context) {
17+
func (h *Handler) updateItem(c *gin.Context) {
1818

1919
}
2020

21-
func (h *MainHandler) deleteItem(c *gin.Context) {
21+
func (h *Handler) deleteItem(c *gin.Context) {
2222

2323
}

pkg/http-server/handlers/list.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ import (
88
"strconv"
99
)
1010

11-
func (h *MainHandler) createList(c *gin.Context) {
11+
func (h *Handler) createList(c *gin.Context) {
1212
id, err := getUserId(c)
1313
if err != nil {
1414
h.logger.Error("User not found in context", slog.String("error", err.Error()))
1515
return
1616
}
1717

1818
var input entity.Todos
19-
if err := c.BindJSON(&input); err != nil {
19+
if err = c.BindJSON(&input); err != nil {
2020
h.logger.Error("error in converting JSON", slog.String("error", err.Error()))
2121
newErrorResponse(c, http.StatusBadRequest, err.Error())
2222
return
@@ -39,7 +39,7 @@ func (h *MainHandler) createList(c *gin.Context) {
3939
h.logger.Info("todo successfully created", slog.Any("response", response))
4040
}
4141

42-
func (h *MainHandler) getAllLists(c *gin.Context) {
42+
func (h *Handler) getAllLists(c *gin.Context) {
4343
id, err := getUserId(c)
4444
if err != nil {
4545
h.logger.Error("User not found in context", slog.String("error", err.Error()))
@@ -60,7 +60,7 @@ func (h *MainHandler) getAllLists(c *gin.Context) {
6060
h.logger.Info("successfully getting all records for user", slog.Any("response", response))
6161
}
6262

63-
func (h *MainHandler) getListById(c *gin.Context) {
63+
func (h *Handler) getListById(c *gin.Context) {
6464
id, err := getUserId(c)
6565
if err != nil {
6666
h.logger.Error("User not found in context", slog.String("error", err.Error()))
@@ -85,7 +85,7 @@ func (h *MainHandler) getListById(c *gin.Context) {
8585
h.logger.Info("successfully getting all records for user", slog.Any("response", list))
8686
}
8787

88-
func (h *MainHandler) updateList(c *gin.Context) {
88+
func (h *Handler) updateList(c *gin.Context) {
8989
id, err := getUserId(c)
9090
if err != nil {
9191
h.logger.Error("User not found in context", slog.String("error", err.Error()))
@@ -100,7 +100,7 @@ func (h *MainHandler) updateList(c *gin.Context) {
100100
}
101101

102102
var input entity.UpdateListInput
103-
if err := c.BindJSON(&input); err != nil {
103+
if err = c.BindJSON(&input); err != nil {
104104
h.logger.Error("error in converting JSON", slog.String("error", err.Error()))
105105
newErrorResponse(c, http.StatusBadRequest, err.Error())
106106
return
@@ -118,7 +118,7 @@ func (h *MainHandler) updateList(c *gin.Context) {
118118
h.logger.Info("successfully update todo", slog.String("Status", "ok"))
119119
}
120120

121-
func (h *MainHandler) deleteList(c *gin.Context) {
121+
func (h *Handler) deleteList(c *gin.Context) {
122122
id, err := getUserId(c)
123123
if err != nil {
124124
h.logger.Error("User not found in context", slog.String("error", err.Error()))

pkg/http-server/handlers/middleware.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const (
1212
userCtx = "userId "
1313
)
1414

15-
func (h *MainHandler) userIdentity(c *gin.Context) {
15+
func (h *Handler) userIdentity(c *gin.Context) {
1616
header := c.GetHeader(authorizationHeader)
1717
if header == "" {
1818
newErrorResponse(c, http.StatusUnauthorized, "No authorization header")
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package slogdiscard
2+
3+
import (
4+
"context"
5+
"log/slog"
6+
)
7+
8+
func NewDiscardLogger() *slog.Logger {
9+
return slog.New(NewDiscardHandler())
10+
}
11+
12+
type DiscardHandler struct{}
13+
14+
func NewDiscardHandler() *DiscardHandler {
15+
return &DiscardHandler{}
16+
}
17+
18+
func (h *DiscardHandler) Handle(_ context.Context, _ slog.Record) error {
19+
return nil
20+
}
21+
22+
func (h *DiscardHandler) WithAttrs(_ []slog.Attr) slog.Handler {
23+
return h
24+
}
25+
26+
func (h *DiscardHandler) WithGroup(_ string) slog.Handler {
27+
return h
28+
}
29+
30+
func (h *DiscardHandler) Enabled(_ context.Context, _ slog.Level) bool {
31+
return false
32+
}

0 commit comments

Comments
 (0)