Skip to content

Commit d036410

Browse files
committed
updated deps and used new feats in heligo
1 parent 7414eee commit d036410

7 files changed

Lines changed: 38 additions & 51 deletions

File tree

api/utils.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ func WriteBadRequest(w http.ResponseWriter, err error) (int, error) {
4949
// WriteServerError write a status related to a database error
5050
func WriteServerError(w http.ResponseWriter, err error) (int, error) {
5151
var status int
52-
if dberr, ok := err.(*pgconn.PgError); ok {
52+
var dberr *pgconn.PgError
53+
if errors.As(err, &dberr) {
5354
switch dberr.Code {
5455
case "42501":
5556
status = http.StatusUnauthorized
@@ -78,7 +79,7 @@ func WriteServerError(w http.ResponseWriter, err error) (int, error) {
7879
} else if errors.Is(err, pgx.ErrNoRows) {
7980
status = http.StatusNotFound
8081
heligo.WriteHeader(w, status)
81-
} else if _, ok := err.(*pgconn.ConnectError); ok {
82+
} else if connectErr := (*pgconn.ConnectError)(nil); errors.As(err, &connectErr) {
8283
status = http.StatusBadRequest
8384
heligo.WriteJSON(w, status, SmoothError{Subsystem: "auth", Message: err.Error()})
8485
} else {

go.mod

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
module github.com/sted/smoothdb
22

3-
go 1.24.0
3+
go 1.26.0
44

55
require (
6-
github.com/golang-jwt/jwt/v5 v5.3.0
7-
github.com/jackc/pgx/v5 v5.7.6
6+
github.com/golang-jwt/jwt/v5 v5.3.1
7+
github.com/jackc/pgx/v5 v5.8.0
88
github.com/rs/cors v1.11.1
99
github.com/rs/zerolog v1.34.0
10-
github.com/samber/lo v1.51.0
11-
github.com/sted/heligo v0.2.3
10+
github.com/samber/lo v1.52.0
11+
github.com/sted/heligo v0.3.0
1212
github.com/tailscale/hujson v0.0.0-20250605163823-992244df8c5a
1313
gopkg.in/natefinch/lumberjack.v2 v2.2.1
1414
)
@@ -20,8 +20,7 @@ require (
2020
github.com/jackc/puddle/v2 v2.2.2 // indirect
2121
github.com/mattn/go-colorable v0.1.14 // indirect
2222
github.com/mattn/go-isatty v0.0.20 // indirect
23-
golang.org/x/crypto v0.42.0 // indirect
24-
golang.org/x/sync v0.17.0 // indirect
25-
golang.org/x/sys v0.36.0 // indirect
26-
golang.org/x/text v0.29.0 // indirect
23+
golang.org/x/sync v0.19.0 // indirect
24+
golang.org/x/sys v0.41.0 // indirect
25+
golang.org/x/text v0.34.0 // indirect
2726
)

go.sum

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,16 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
33
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
44
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
55
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
6-
github.com/golang-jwt/jwt/v5 v5.2.2 h1:Rl4B7itRWVtYIHFrSNd7vhTiz9UpLdi6gZhZ3wEeDy8=
7-
github.com/golang-jwt/jwt/v5 v5.2.2/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
8-
github.com/golang-jwt/jwt/v5 v5.3.0 h1:pv4AsKCKKZuqlgs5sUmn4x8UlGa0kEVt/puTpKx9vvo=
9-
github.com/golang-jwt/jwt/v5 v5.3.0/go.mod h1:fxCRLWMO43lRc8nhHWY6LGqRcf+1gQWArsqaEUEa5bE=
6+
github.com/golang-jwt/jwt/v5 v5.3.1 h1:kYf81DTWFe7t+1VvL7eS+jKFVWaUnK9cB1qbwn63YCY=
7+
github.com/golang-jwt/jwt/v5 v5.3.1/go.mod h1:fxCRLWMO43lRc8nhHWY6LGqRcf+1gQWArsqaEUEa5bE=
108
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
119
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
1210
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
1311
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
1412
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
1513
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
16-
github.com/jackc/pgx/v5 v5.7.4 h1:9wKznZrhWa2QiHL+NjTSPP6yjl3451BX3imWDnokYlg=
17-
github.com/jackc/pgx/v5 v5.7.4/go.mod h1:ncY89UGWxg82EykZUwSpUKEfccBGGYq1xjrOpsbsfGQ=
18-
github.com/jackc/pgx/v5 v5.7.6 h1:rWQc5FwZSPX58r1OQmkuaNicxdmExaEz5A2DO2hUuTk=
19-
github.com/jackc/pgx/v5 v5.7.6/go.mod h1:aruU7o91Tc2q2cFp5h4uP3f6ztExVpyVv88Xl/8Vl8M=
14+
github.com/jackc/pgx/v5 v5.8.0 h1:TYPDoleBBme0xGSAX3/+NujXXtpZn9HBONkQC7IEZSo=
15+
github.com/jackc/pgx/v5 v5.8.0/go.mod h1:QVeDInX2m9VyzvNeiCJVjCkNFqzsNb43204HshNSZKw=
2016
github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo=
2117
github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
2218
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
@@ -34,36 +30,26 @@ github.com/rs/cors v1.11.1/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU
3430
github.com/rs/xid v1.6.0/go.mod h1:7XoLgs4eV+QndskICGsho+ADou8ySMSjJKDIan90Nz0=
3531
github.com/rs/zerolog v1.34.0 h1:k43nTLIwcTVQAncfCw4KZ2VY6ukYoZaBPNOE8txlOeY=
3632
github.com/rs/zerolog v1.34.0/go.mod h1:bJsvje4Z08ROH4Nhs5iH600c3IkWhwp44iRc54W6wYQ=
37-
github.com/samber/lo v1.51.0 h1:kysRYLbHy/MB7kQZf5DSN50JHmMsNEdeY24VzJFu7wI=
38-
github.com/samber/lo v1.51.0/go.mod h1:4+MXEGsJzbKGaUEQFKBq2xtfuznW9oz/WrgyzMzRoM0=
39-
github.com/sted/heligo v0.2.3 h1:YPE5G0XQp4/hpsVpIwlBlTNN14Soa/DXVp1Vnh/BiiA=
40-
github.com/sted/heligo v0.2.3/go.mod h1:4V4lUjw9DWR3VkO0JLeQRY+rGQBmT0m/Kn0qtwDNx5I=
33+
github.com/samber/lo v1.52.0 h1:Rvi+3BFHES3A8meP33VPAxiBZX/Aws5RxrschYGjomw=
34+
github.com/samber/lo v1.52.0/go.mod h1:4+MXEGsJzbKGaUEQFKBq2xtfuznW9oz/WrgyzMzRoM0=
35+
github.com/sted/heligo v0.3.0 h1:D5DpF+kZJdfpKpLNfwMlrr4kGksSTdVNXpJFWkajyMs=
36+
github.com/sted/heligo v0.3.0/go.mod h1:ABeimWAZrNRmHngSfQhEF96yrVeceW2JVS2J2GwbtSo=
4137
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
4238
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
4339
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
44-
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
45-
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
40+
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
41+
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
4642
github.com/tailscale/hujson v0.0.0-20250605163823-992244df8c5a h1:a6TNDN9CgG+cYjaeN8l2mc4kSz2iMiCDQxPEyltUV/I=
4743
github.com/tailscale/hujson v0.0.0-20250605163823-992244df8c5a/go.mod h1:EbW0wDK/qEUYI0A5bqq0C2kF8JTQwWONmGDBbzsxxHo=
48-
golang.org/x/crypto v0.39.0 h1:SHs+kF4LP+f+p14esP5jAoDpHU8Gu/v9lFRK6IT5imM=
49-
golang.org/x/crypto v0.39.0/go.mod h1:L+Xg3Wf6HoL4Bn4238Z6ft6KfEpN0tJGo53AAPC632U=
50-
golang.org/x/crypto v0.42.0 h1:chiH31gIWm57EkTXpwnqf8qeuMUi0yekh6mT2AvFlqI=
51-
golang.org/x/crypto v0.42.0/go.mod h1:4+rDnOTJhQCx2q7/j6rAN5XDw8kPjeaXEUR2eL94ix8=
52-
golang.org/x/sync v0.15.0 h1:KWH3jNZsfyT6xfAfKiz6MRNmd46ByHDYaZ7KSkCtdW8=
53-
golang.org/x/sync v0.15.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
54-
golang.org/x/sync v0.17.0 h1:l60nONMj9l5drqw6jlhIELNv9I0A4OFgRsG9k2oT9Ug=
55-
golang.org/x/sync v0.17.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
44+
golang.org/x/sync v0.19.0 h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4=
45+
golang.org/x/sync v0.19.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
5646
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
5747
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
5848
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
59-
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
60-
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
61-
golang.org/x/sys v0.36.0 h1:KVRy2GtZBrk1cBYA7MKu5bEZFxQk4NIDV6RLVcC8o0k=
62-
golang.org/x/sys v0.36.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
63-
golang.org/x/text v0.26.0 h1:P42AVeLghgTYr4+xUnTRKDMqpar+PtX7KWuNQL21L8M=
64-
golang.org/x/text v0.26.0/go.mod h1:QK15LZJUUQVJxhz7wXgxSy/CJaTFjd0G+YLonydOVQA=
65-
golang.org/x/text v0.29.0 h1:1neNs90w9YzJ9BocxfsQNHKuAT4pkghyXc4nhZ6sJvk=
66-
golang.org/x/text v0.29.0/go.mod h1:7MhJOA9CD2qZyOKYazxdYMF85OwPdEr9jTtBpO7ydH4=
49+
golang.org/x/sys v0.41.0 h1:Ivj+2Cp/ylzLiEU89QhWblYnOE9zerudt9Ftecq2C6k=
50+
golang.org/x/sys v0.41.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
51+
golang.org/x/text v0.34.0 h1:oL/Qq0Kdaqxa1KbNeMKwQq0reLCCaFtqu2eNuSeNHbk=
52+
golang.org/x/text v0.34.0/go.mod h1:homfLqTYRFyVYemLBFl5GgL/DWEiH5wcsQ5gSh1yziA=
6753
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
6854
gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc=
6955
gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc=

server/http_server.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ import (
1111

1212
func (s *Server) initHTTPServer() {
1313
s.router = heligo.New()
14-
//router.Use(gin.Recovery())
14+
s.router.TrailingSlash = true
15+
s.router.Use(heligo.Recover(func(v any) {
16+
s.logger.Error().Msgf("panic recovered: %v", v)
17+
}))
18+
s.router.Use(heligo.CleanPaths())
1519
s.router.Use(HTTPLogger(s.logger))
1620

1721
cfg := s.Config

test/api/bench_test.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"net/http"
66
"net/http/httptest"
7+
"strings"
78
"testing"
89

910
"github.com/sted/heligo"
@@ -65,17 +66,13 @@ func BenchmarkBase(b *testing.B) {
6566
}
6667

6768
for _, t := range tests {
68-
w := httptest.NewRecorder()
69-
req, err := http.NewRequest(t.Method, t.Query, nil)
70-
req.Header.Add("Authorization", user1Token)
71-
if err != nil {
72-
panic(err)
73-
}
7469
b.Run(t.Description, func(b *testing.B) {
7570
for i := 0; i < b.N; i++ {
71+
w := httptest.NewRecorder()
72+
req, _ := http.NewRequest(t.Method, t.Query, strings.NewReader(""))
73+
req.Header.Add("Authorization", user1Token)
7674
router.ServeHTTP(w, req)
7775
}
78-
7976
})
8077
}
8178
}

test/api/main_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func TestMain(m *testing.M) {
2222
"Address": "localhost:8082",
2323
"AllowAnon": false,
2424
"EnableAdminRoute": true,
25-
"Database.URL": "postgresql://postgres:@localhost:5432/postgres",
25+
"Database.URL": "postgresql://postgres:postgres@localhost:5432/postgres",
2626
"Logging.Level": "info",
2727
"Logging.FileLogging": true,
2828
"Logging.FilePath": "../../smoothdb.log",

test/postgrest/main_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func TestMain(m *testing.M) {
2222
"Logging.FileLogging": true,
2323
"Logging.FilePath": "../../smoothdb.log",
2424
"Logging.StdOut": false,
25-
"Database.URL": "postgresql://postgres:@localhost:5432/postgres",
25+
"Database.URL": "postgresql://postgres:postgres@localhost:5432/postgres",
2626
"Database.SchemaSearchPath": []string{"test"},
2727
"Database.TransactionMode": "rollback-allow-override",
2828
}

0 commit comments

Comments
 (0)