From d1dc5897c56bafd4ae9822489c8268d5c8830e6f Mon Sep 17 00:00:00 2001 From: Ron Rise Date: Tue, 10 Jun 2025 08:14:17 -0400 Subject: [PATCH] fix tpyo --- .gitea/workflows/tests.yml | 26 ++++++++++++++++++++++++ backend/.golangci.yml | 17 ++++++++++++++++ backend/database/conn.go | 22 ++++++++++++++++++++ backend/database/migrate.go | 3 +++ backend/go.mod | 14 ++++++------- backend/go.sum | 16 +++++++++++++++ backend/handlers/bullets/handler.go | 23 +++++++++++++++------ backend/handlers/cartridge/handler.go | 12 ++++++++--- backend/handlers/loads/handler.go | 6 +++--- backend/handlers/manufacturer/handler.go | 12 ++++++++--- backend/handlers/powder/handler.go | 16 +++++++++++---- backend/handlers/primers/handler.go | 19 ++++++++++++----- backend/handlers/responses_test.go | 1 - backend/handlers/uuid.go | 1 - backend/main.go | 4 +++- 15 files changed, 158 insertions(+), 34 deletions(-) create mode 100644 backend/.golangci.yml diff --git a/.gitea/workflows/tests.yml b/.gitea/workflows/tests.yml index a51627d..7ce991f 100644 --- a/.gitea/workflows/tests.yml +++ b/.gitea/workflows/tests.yml @@ -38,6 +38,32 @@ jobs: cd frontend npm run build + golangci-lint: + name: ๐Ÿงช ๐Ÿน GolangCI-Lint + runs-on: ubuntu-latest + steps: + - name: ๐Ÿ›ก๏ธ ๐Ÿ”’ Add Siteworx CA Certificates + run: | + apt update && apt install -yq ca-certificates curl + curl -Ls https://siteworxpro.com/hosted/Siteworx+Root+CA.pem -o /usr/local/share/ca-certificates/sw.crt + update-ca-certificates + - name: ๐Ÿ“– ๐Ÿ” Checkout Repository Code + uses: actions/checkout@v2 + with: + fetch-depth: 1 + - name: โš™๏ธ ๐Ÿน Set up Go Environment + uses: actions/setup-go@v2 + with: + go-version: '1.24.3' + cache: true + - name: ๐Ÿ“ฆ ๐Ÿ“ฅ Install GolangCI-Lint + run: | + go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest + - name: โœ… ๐Ÿงช Run GolangCI-Lint + run: | + cd backend + golangci-lint run --timeout 5m --config .golangci.yml + test-go: env: GOPRIVATE: 'git.siteworxpro.com' diff --git a/backend/.golangci.yml b/backend/.golangci.yml new file mode 100644 index 0000000..5912633 --- /dev/null +++ b/backend/.golangci.yml @@ -0,0 +1,17 @@ +version: "2" +linters: + default: standard + enable: + - whitespace + - wrapcheck + - tagalign + - reassign + - bodyclose + - contextcheck + - containedctx + - godot + +formatters: + settings: + gofmt: + simplify: true diff --git a/backend/database/conn.go b/backend/database/conn.go index 3160c4d..a2c389d 100644 --- a/backend/database/conn.go +++ b/backend/database/conn.go @@ -20,6 +20,10 @@ const ( DbPassword Env.EnvironmentVariable = "DB_PASSWORD" ) +type contextKeyType string + +const dbContextKey contextKeyType = "dbcontext" + type Database struct { Db *pgx.Conn connected bool @@ -50,6 +54,24 @@ func (*Database) DSN(hidePassword bool) string { return fmt.Sprintf("postgres://%s:%s@%s:5432/%s%s", dbUser, dbPassword, dbHost, dbDatabase, extraParams) } +func NewWithContext(ctx context.Context) context.Context { + db := GetNewDatabase() + + return context.WithValue(ctx, dbContextKey, db) +} + +func NewFromContext(ctx context.Context) *Database { + if ok := ctx.Value(dbContextKey); ok != nil { + return ctx.Value(dbContextKey).(*Database) + } + + return nil +} + +func WithContext(ctx context.Context, database *Database) context.Context { + return context.WithValue(ctx, dbContextKey, database) +} + func GetNewDatabase() *Database { var dbSingleton Database diff --git a/backend/database/migrate.go b/backend/database/migrate.go index 991ae73..9ef1e20 100644 --- a/backend/database/migrate.go +++ b/backend/database/migrate.go @@ -11,6 +11,9 @@ import ( func (db *Database) Migrate() { sqlDB, err := sql.Open("postgres", db.DSN(false)) + if err != nil { + log.Fatal(err) + } driver, err := postgres.WithInstance(sqlDB, &postgres.Config{ MigrationsTable: "schema_migrations", diff --git a/backend/go.mod b/backend/go.mod index 4ed7f73..c89300e 100644 --- a/backend/go.mod +++ b/backend/go.mod @@ -9,8 +9,8 @@ require ( github.com/go-sql-driver/mysql v1.9.2 github.com/golang-migrate/migrate v3.5.4+incompatible github.com/google/uuid v1.6.0 - github.com/jackc/pgx/v5 v5.7.4 - github.com/labstack/echo/v4 v4.13.3 + github.com/jackc/pgx/v5 v5.7.5 + github.com/labstack/echo/v4 v4.13.4 github.com/labstack/gommon v0.4.2 ) @@ -41,11 +41,11 @@ require ( github.com/stretchr/testify v1.10.0 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/fasttemplate v1.2.2 // indirect - golang.org/x/crypto v0.37.0 // indirect - golang.org/x/net v0.39.0 // indirect - golang.org/x/sys v0.32.0 // indirect - golang.org/x/text v0.24.0 // indirect - golang.org/x/time v0.11.0 // indirect + golang.org/x/crypto v0.39.0 // indirect + golang.org/x/net v0.41.0 // indirect + golang.org/x/sys v0.33.0 // indirect + golang.org/x/text v0.26.0 // indirect + golang.org/x/time v0.12.0 // indirect gopkg.in/go-playground/assert.v1 v1.2.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/backend/go.sum b/backend/go.sum index 7b05b45..1ff03ac 100644 --- a/backend/go.sum +++ b/backend/go.sum @@ -42,6 +42,8 @@ github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7Ulw github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= github.com/jackc/pgx/v5 v5.7.4 h1:9wKznZrhWa2QiHL+NjTSPP6yjl3451BX3imWDnokYlg= github.com/jackc/pgx/v5 v5.7.4/go.mod h1:ncY89UGWxg82EykZUwSpUKEfccBGGYq1xjrOpsbsfGQ= +github.com/jackc/pgx/v5 v5.7.5 h1:JHGfMnQY+IEtGM63d+NGMjoRpysB2JBwDr5fsngwmJs= +github.com/jackc/pgx/v5 v5.7.5/go.mod h1:aruU7o91Tc2q2cFp5h4uP3f6ztExVpyVv88Xl/8Vl8M= github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo= github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= @@ -52,6 +54,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/labstack/echo/v4 v4.13.3 h1:pwhpCPrTl5qry5HRdM5FwdXnhXSLSY+WE+YQSeCaafY= github.com/labstack/echo/v4 v4.13.3/go.mod h1:o90YNEeQWjDozo584l7AwhJMHN0bOC4tAfg+Xox9q5g= +github.com/labstack/echo/v4 v4.13.4 h1:oTZZW+T3s9gAu5L8vmzihV7/lkXGZuITzTQkTEhcXEA= +github.com/labstack/echo/v4 v4.13.4/go.mod h1:g63b33BZ5vZzcIUF8AtRH40DrTlXnx4UMC8rBdndmjQ= github.com/labstack/gommon v0.4.2 h1:F8qTUNXgG1+6WQmqoUWnz8WiEU60mXVVw0P4ht1WRA0= github.com/labstack/gommon v0.4.2/go.mod h1:QlUFxVM+SNXhDL/Z7YhocGIBYOiwB0mXm1+1bAPHPyU= github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ= @@ -88,33 +92,45 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.37.0 h1:kJNSjF/Xp7kU0iB2Z+9viTPMW4EqqsrywMXLJOOsXSE= golang.org/x/crypto v0.37.0/go.mod h1:vg+k43peMZ0pUMhYmVAWysMK35e6ioLh3wB8ZCAfbVc= +golang.org/x/crypto v0.39.0 h1:SHs+kF4LP+f+p14esP5jAoDpHU8Gu/v9lFRK6IT5imM= +golang.org/x/crypto v0.39.0/go.mod h1:L+Xg3Wf6HoL4Bn4238Z6ft6KfEpN0tJGo53AAPC632U= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.21.0 h1:vvrHzRwRfVKSiLrG+d4FMl/Qi4ukBCE6kZlTUkDYRT0= golang.org/x/mod v0.21.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY= +golang.org/x/mod v0.25.0 h1:n7a+ZbQKQA/Ysbyb0/6IbB1H/X41mKgbhfv7AfG/44w= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.39.0 h1:ZCu7HMWDxpXpaiKdhzIfaltL9Lp31x/3fCP11bc6/fY= golang.org/x/net v0.39.0/go.mod h1:X7NRbYVEA+ewNkCNyJ513WmMdQ3BineSwVtN2zD/d+E= +golang.org/x/net v0.41.0 h1:vBTly1HeNPEn3wtREYfy4GZ/NECgw2Cnl+nK6Nz3uvw= +golang.org/x/net v0.41.0/go.mod h1:B/K4NNqkfmg07DQYrbwvSluqCJOOXwUjeb/5lOisjbA= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.13.0 h1:AauUjRAJ9OSnvULf/ARrrVywoJDy0YS2AwQ98I37610= golang.org/x/sync v0.13.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= +golang.org/x/sync v0.15.0 h1:KWH3jNZsfyT6xfAfKiz6MRNmd46ByHDYaZ7KSkCtdW8= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.32.0 h1:s77OFDvIQeibCmezSnk/q6iAfkdiQaJi4VzroCFrN20= golang.org/x/sys v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= +golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw= +golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.24.0 h1:dd5Bzh4yt5KYA8f9CJHCP4FB4D51c2c6JvN37xJJkJ0= golang.org/x/text v0.24.0/go.mod h1:L8rBsPeo2pSS+xqN0d5u2ikmjtmoJbDBT1b7nHvFCdU= +golang.org/x/text v0.26.0 h1:P42AVeLghgTYr4+xUnTRKDMqpar+PtX7KWuNQL21L8M= +golang.org/x/text v0.26.0/go.mod h1:QK15LZJUUQVJxhz7wXgxSy/CJaTFjd0G+YLonydOVQA= golang.org/x/time v0.11.0 h1:/bpjEDfN9tkoN/ryeYHnv5hcMlc8ncjMcM4XBk5NWV0= golang.org/x/time v0.11.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg= +golang.org/x/time v0.12.0 h1:ScB/8o8olJvc+CQPWrK3fPZNfh7qgwCrY0zJmoEQLSE= +golang.org/x/time v0.12.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= diff --git a/backend/handlers/bullets/handler.go b/backend/handlers/bullets/handler.go index 67d0a69..d4a0332 100644 --- a/backend/handlers/bullets/handler.go +++ b/backend/handlers/bullets/handler.go @@ -21,7 +21,10 @@ type BulletResponse struct { func Photo(c echo.Context) error { db := c.(*database.CustomContext).Db - defer db.Db.Close(context.Background()) + + defer func() { + _ = db.Db.Close(context.Background()) + }() id := c.Param("id") uid := handlers.ParseUuidOrBadRequest(c, id) @@ -48,7 +51,10 @@ func Photo(c echo.Context) error { func Delete(c echo.Context) error { db := c.(*database.CustomContext).Db - defer db.Db.Close(context.Background()) + + defer func() { + _ = db.Db.Close(context.Background()) + }() id := c.Param("id") uid := handlers.ParseUuidOrBadRequest(c, id) @@ -66,7 +72,9 @@ func Delete(c echo.Context) error { func Put(c echo.Context) error { db := c.(*database.CustomContext).Db - defer db.Db.Close(context.Background()) + defer func() { + _ = db.Db.Close(context.Background()) + }() id := c.Param("id") uid := handlers.ParseUuidOrBadRequest(c, id) @@ -147,7 +155,9 @@ func Put(c echo.Context) error { func Get(c echo.Context) error { db := c.(*database.CustomContext).Db - defer db.Db.Close(context.Background()) + defer func() { + _ = db.Db.Close(context.Background()) + }() if c.Param("id") != "" { id := c.Param("id") @@ -210,7 +220,6 @@ func Get(c echo.Context) error { } func Post(c echo.Context) error { - file, err := c.FormFile("photo") if err != nil { c.Logger().Error(err) @@ -245,7 +254,9 @@ func Post(c echo.Context) error { } db := c.(*database.CustomContext).Db - defer db.Db.Close(context.Background()) + defer func() { + _ = db.Db.Close(context.Background()) + }() manufacturerUid := handlers.ParseUuidOrBadRequest(c, manufacturerId) if manufacturerUid == nil { diff --git a/backend/handlers/cartridge/handler.go b/backend/handlers/cartridge/handler.go index 5043940..85c9441 100644 --- a/backend/handlers/cartridge/handler.go +++ b/backend/handlers/cartridge/handler.go @@ -22,7 +22,9 @@ type postRequest struct { func Get(c echo.Context) error { db := c.(*database.CustomContext).Db - defer db.Db.Close(context.Background()) + defer func() { + _ = db.Db.Close(context.Background()) + }() cartridges, err := db.Loads.GetCartridges(context.Background()) if err != nil { @@ -45,7 +47,9 @@ func Get(c echo.Context) error { func Post(c echo.Context) error { db := c.(*database.CustomContext).Db - defer db.Db.Close(context.Background()) + defer func() { + _ = db.Db.Close(context.Background()) + }() req := postRequest{} @@ -79,7 +83,9 @@ func Post(c echo.Context) error { func Delete(c echo.Context) error { db := c.(*database.CustomContext).Db - defer db.Db.Close(context.Background()) + defer func() { + _ = db.Db.Close(context.Background()) + }() uid := handlers.ParseUuidOrBadRequest(c, c.Param("id")) if uid == nil { diff --git a/backend/handlers/loads/handler.go b/backend/handlers/loads/handler.go index 7c70239..ea3f26d 100644 --- a/backend/handlers/loads/handler.go +++ b/backend/handlers/loads/handler.go @@ -66,7 +66,9 @@ type ResultChan[T any] struct { func Post(c echo.Context) error { db := c.(*database.CustomContext).Db - defer db.Db.Close(context.Background()) + defer func() { + _ = db.Db.Close(context.Background()) + }() cartridgeID, err := handlers.ParseUuid(c.FormValue("cartridge_id")) if err != nil { @@ -136,7 +138,6 @@ func Post(c echo.Context) error { } func Get(c echo.Context) error { - id := c.Param("id") cResults := make(chan ResultChan[[]loadResponseResults]) @@ -182,7 +183,6 @@ func Get(c echo.Context) error { } else { ch <- ResultChan[int64]{Result: total} } - }(cTotal) go execResultsQuery(cResults, c) diff --git a/backend/handlers/manufacturer/handler.go b/backend/handlers/manufacturer/handler.go index b4fe176..f00e4c7 100644 --- a/backend/handlers/manufacturer/handler.go +++ b/backend/handlers/manufacturer/handler.go @@ -21,7 +21,9 @@ type manufacturerResponse struct { func Get(c echo.Context) error { db := c.(*database.CustomContext).Db - defer db.Db.Close(context.Background()) + defer func() { + _ = db.Db.Close(context.Background()) + }() if c.Param("id") != "" { id := c.Param("id") @@ -73,7 +75,9 @@ func Get(c echo.Context) error { func Delete(c echo.Context) error { db := c.(*database.CustomContext).Db - defer db.Db.Close(context.Background()) + defer func() { + _ = db.Db.Close(context.Background()) + }() id := c.Param("id") uid := handlers.ParseUuidOrBadRequest(c, id) @@ -97,7 +101,9 @@ func Delete(c echo.Context) error { func Post(c echo.Context) error { db := c.(*database.CustomContext).Db - defer db.Db.Close(context.Background()) + defer func() { + _ = db.Db.Close(context.Background()) + }() if c.Param("id") != "" { id := c.Param("id") diff --git a/backend/handlers/powder/handler.go b/backend/handlers/powder/handler.go index e698a6f..f4cf6af 100644 --- a/backend/handlers/powder/handler.go +++ b/backend/handlers/powder/handler.go @@ -13,7 +13,9 @@ import ( func Photo(c echo.Context) error { db := c.(*database.CustomContext).Db - defer db.Db.Close(context.Background()) + defer func() { + _ = db.Db.Close(context.Background()) + }() id := c.Param("id") uid, err := handlers.ParseUuid(id) @@ -41,7 +43,9 @@ func Photo(c echo.Context) error { func Delete(c echo.Context) error { id := c.Param("id") db := c.(*database.CustomContext).Db - defer db.Db.Close(context.Background()) + defer func() { + _ = db.Db.Close(context.Background()) + }() uid, err := handlers.ParseUuid(id) if err != nil { @@ -58,7 +62,9 @@ func Delete(c echo.Context) error { func Post(c echo.Context) error { db := c.(*database.CustomContext).Db - defer db.Db.Close(context.Background()) + defer func() { + _ = db.Db.Close(context.Background()) + }() if c.Param("id") != "" { id := c.Param("id") @@ -163,7 +169,9 @@ func Post(c echo.Context) error { func Get(c echo.Context) error { db := c.(*database.CustomContext).Db - defer db.Db.Close(context.Background()) + defer func() { + _ = db.Db.Close(context.Background()) + }() if c.Param("id") != "" { id := c.Param("id") diff --git a/backend/handlers/primers/handler.go b/backend/handlers/primers/handler.go index fbb7676..2ba7b01 100644 --- a/backend/handlers/primers/handler.go +++ b/backend/handlers/primers/handler.go @@ -19,7 +19,9 @@ type PrimerResponse struct { func Delete(c echo.Context) error { db := c.(*database.CustomContext).Db - defer db.Db.Close(context.Background()) + defer func() { + _ = db.Db.Close(context.Background()) + }() id := c.Param("id") uid, err := handlers.ParseUuid(id) @@ -37,7 +39,9 @@ func Delete(c echo.Context) error { func Post(c echo.Context) error { db := c.(*database.CustomContext).Db - defer db.Db.Close(context.Background()) + defer func() { + _ = db.Db.Close(context.Background()) + }() if c.Param("id") != "" { id := c.Param("id") @@ -112,7 +116,8 @@ func Post(c echo.Context) error { if metaString == "" { metaString = "{}" } - var meta json.RawMessage = []byte(metaString) + + meta := []byte(metaString) newUuid := uuid.New().String() uid, _ := handlers.ParseUuid(newUuid) @@ -145,7 +150,9 @@ func Post(c echo.Context) error { func Photo(c echo.Context) error { db := c.(*database.CustomContext).Db - defer db.Db.Close(context.Background()) + defer func() { + _ = db.Db.Close(context.Background()) + }() id := c.Param("id") uid := handlers.ParseUuidOrBadRequest(c, id) @@ -172,7 +179,9 @@ func Photo(c echo.Context) error { func Get(c echo.Context) error { db := c.(*database.CustomContext).Db - defer db.Db.Close(context.Background()) + defer func() { + _ = db.Db.Close(context.Background()) + }() if c.Param("id") != "" { id := c.Param("id") diff --git a/backend/handlers/responses_test.go b/backend/handlers/responses_test.go index 0c3671b..37fc3e6 100644 --- a/backend/handlers/responses_test.go +++ b/backend/handlers/responses_test.go @@ -11,7 +11,6 @@ type TestContext struct { } func (t TestContext) JSON(code int, i interface{}) error { - if code != 400 { t.t.Fatal("expected 400") } diff --git a/backend/handlers/uuid.go b/backend/handlers/uuid.go index 07f842e..c43657d 100644 --- a/backend/handlers/uuid.go +++ b/backend/handlers/uuid.go @@ -41,5 +41,4 @@ func ParseUuidOrBadRequest(c echo.Context, s string) *pgtype.UUID { } return uid - } diff --git a/backend/main.go b/backend/main.go index a1d8180..5928ad2 100644 --- a/backend/main.go +++ b/backend/main.go @@ -114,7 +114,9 @@ func migrate(e *echo.Echo) { db := database.GetNewDatabase() - defer db.Db.Close(context.Background()) + defer func() { + _ = db.Db.Close(context.Background()) + }() db.Migrate() e.Logger.Info("โœ… Complete!")