Skip to content

Commit

Permalink
Merge pull request #202 from bfabio/fiber
Browse files Browse the repository at this point in the history
Upgrade to Fiber 2.46
  • Loading branch information
bfabio committed Jun 16, 2023
2 parents 61344d7 + 5d67ae6 commit 66043af
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 27 deletions.
24 changes: 16 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/go-playground/validator/v10 v10.11.0
github.com/go-testfixtures/testfixtures/v3 v3.8.0
github.com/gofiber/contrib/paseto v0.0.0-20220621082844-83549332c36e
github.com/gofiber/fiber/v2 v2.36.0
github.com/gofiber/fiber/v2 v2.46.0
github.com/jackc/pgerrcode v0.0.0-20220416144525-469b46aa5efa
github.com/stretchr/testify v1.7.5
gorm.io/driver/postgres v1.3.7
Expand All @@ -26,13 +26,21 @@ require (
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/gofiber/adaptor/v2 v2.1.25 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.18 // indirect
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/mattn/go-sqlite3 v1.14.16 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/philhofer/fwd v1.1.2 // indirect
github.com/prometheus/client_golang v1.12.2 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.32.1 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
golang.org/x/net v0.7.0 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/savsgio/dictpool v0.0.0-20221023140959-7bf2e61cea94 // indirect
github.com/savsgio/gotils v0.0.0-20230208104028-c358bd845dee // indirect
github.com/tinylib/msgp v1.1.8 // indirect
golang.org/x/net v0.8.0 // indirect
google.golang.org/protobuf v1.26.0 // indirect
)

Expand All @@ -47,7 +55,7 @@ require (
)

require (
github.com/andybalholm/brotli v1.0.4 // indirect
github.com/andybalholm/brotli v1.0.5 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-playground/locales v0.14.0 // indirect
github.com/go-playground/universal-translator v0.18.0 // indirect
Expand All @@ -61,15 +69,15 @@ require (
github.com/jackc/pgx/v4 v4.16.1 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/klauspost/compress v1.15.7 // indirect
github.com/klauspost/compress v1.16.3 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.38.0 // indirect
github.com/valyala/fasthttp v1.47.0 // indirect
github.com/valyala/tcplisten v1.0.0 // indirect
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/text v0.7.0 // indirect
golang.org/x/crypto v0.7.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/text v0.8.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
57 changes: 57 additions & 0 deletions go.sum

Large diffs are not rendered by default.

12 changes: 4 additions & 8 deletions internal/handlers/general/pagination.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package general
import (
"encoding/json"
"fmt"
"strconv"

"github.com/gofiber/fiber/v2"
"github.com/pilagod/gorm-cursor-paginator/v2/paginator"
Expand Down Expand Up @@ -48,13 +47,10 @@ func NewPaginatorWithConfig(ctx *fiber.Ctx, config *paginator.Config) *paginator
paginator.SetBeforeCursor(before)
}

if size := ctx.Query("page[size]"); size != "" {
//nolint:godox // need to implement this in the future
// TODO: make the API return the error if limit is not an integer
if limit, err := strconv.Atoi(size); err == nil {
paginator.SetLimit(limit)
}
}
//nolint:godox // need to implement this in the future
// TODO: make the API return the error if limit is not an integer
size := ctx.QueryInt("page[size]", DefaultLimitCount)
paginator.SetLimit(size)

return paginator
}
Expand Down
2 changes: 1 addition & 1 deletion internal/handlers/publishers.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (p *Publisher) GetPublishers(ctx *fiber.Ctx) error {

stmt := p.db.Preload("CodeHosting")

if all := ctx.Query("all", ""); all == "" {
if all := ctx.QueryBool("all", false); !all {
stmt = stmt.Scopes(models.Active)
}

Expand Down
2 changes: 1 addition & 1 deletion internal/handlers/software.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (p *Software) GetAllSoftware(ctx *fiber.Ctx) error { //nolint:cyclop // mos

stmt.Where("id = ?", softwareURL.SoftwareID)
} else {
if all := ctx.Query("all", ""); all == "" {
if all := ctx.QueryBool("all", false); !all {
stmt = stmt.Scopes(models.Active)
}
}
Expand Down
17 changes: 9 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,10 @@ func Setup() *fiber.App {

app.Use(cache.New(cache.Config{
Next: func(ctx *fiber.Ctx) bool {
// Don't cache POST, PUT, PATCH or /status
return ctx.Method() != fiber.MethodGet || ctx.Route().Path == "/v1/status"
// Don't cache /status
return ctx.Route().Path == "/v1/status"
},
Methods: []string{fiber.MethodGet, fiber.MethodHead},
CacheControl: true,
Expiration: 10 * time.Second, //nolint:gomnd
KeyGenerator: func(ctx *fiber.Ctx) string {
Expand Down Expand Up @@ -133,16 +134,16 @@ func setupHandlers(app *fiber.App, gormDB *gorm.DB) {
v1.Delete("/software/:id", softwareHandler.DeleteSoftware)

v1.Get("/logs", logHandler.GetLogs)
v1.Get("/logs/:id", logHandler.GetLog)
v1.Get("/logs/:id<guid>", logHandler.GetLog)
v1.Post("/logs", logHandler.PostLog)
v1.Patch("/logs/:id", logHandler.PatchLog)
v1.Delete("/logs/:id", logHandler.DeleteLog)
v1.Patch("/logs/:id<guid>", logHandler.PatchLog)
v1.Delete("/logs/:id<guid>", logHandler.DeleteLog)
v1.Get("/software/:id/logs", logHandler.GetSoftwareLogs)
v1.Post("/software/:id/logs", logHandler.PostSoftwareLog)

v1.Get("/status", statusHandler.GetStatus)

v1.Get("/webhooks/:id", publisherWebhookHandler.GetWebhook)
v1.Patch("/webhooks/:id", publisherWebhookHandler.PatchWebhook)
v1.Delete("/webhooks/:id", publisherWebhookHandler.DeleteWebhook)
v1.Get("/webhooks/:id<guid>", publisherWebhookHandler.GetWebhook)
v1.Patch("/webhooks/:id<guid>", publisherWebhookHandler.PatchWebhook)
v1.Delete("/webhooks/:id<guid>", publisherWebhookHandler.DeleteWebhook)
}
5 changes: 4 additions & 1 deletion main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2979,7 +2979,10 @@ func TestWebhooksEndpoints(t *testing.T) {
"Content-Type": {"application/json"},
},
expectedCode: 404,
expectedBody: `{"title":"can't delete Webhook","detail":"Webhook was not found","status":404}`,
// This error is different from because it's returned directly from Fiber's
// route constraints, so we don't need to hit the database to find the resource
// because we already know that's not a valid webhook id looking at its format.
expectedBody: `{"title":"Not Found","detail":"Cannot DELETE /v1/webhooks/NO_SUCH_WEBHOOK","status":404}`,
expectedContentType: "application/problem+json",
},
{
Expand Down

0 comments on commit 66043af

Please sign in to comment.