Skip to content

Commit

Permalink
Update to Mojito v0.0.19 (#67)
Browse files Browse the repository at this point in the history
* Update to mojito v0.0.19

* Update workflows

* Improve error logging
  • Loading branch information
0SkillAllLuck authored Dec 9, 2024
1 parent 2321ba8 commit b5079eb
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 93 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
name: GoLint
strategy:
matrix:
go-version: [1.20.x]
go-version: [1.23.x]
runs-on: ubuntu-latest
steps:
- name: Install Go
Expand Down
50 changes: 3 additions & 47 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,51 +24,7 @@ jobs:
with:
go-version: ${{ matrix.go-version }}
check-latest: true
- name: Setup Go Caches
uses: actions/cache@v4
with:
path: |
~/go/pkg/mod
~/.cache/go-build
~/Library/Caches/go-build
~\AppData\Local\go-build
key: ${{ runner.os }}-go-${{ matrix.go-version }}-test-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-${{ matrix.go-version }}-test-
- name: Install dependencies
run: go get .
- name: Run Tests
run: |
go mod download
go test ./... -v -race
gosec-test:
name: GoSec Test
runs-on: ubuntu-latest
permissions:
security-events: write
actions: read
contents: read
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Run GoSec
uses: securego/gosec@master
with:
args: -fmt sarif -out gosec.sarif -exclude-dir=internal/*/ ./...
- name: Upload SARIF file
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: gosec.sarif
govulncheck-test:
name: GoVulnCheck Test
runs-on: ubuntu-latest
permissions:
security-events: write
actions: read
contents: read
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Run Govulncheck
uses: kmulvey/govulncheck-action@v1.2.0
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
fail-on-vuln: true
run: go test ./... -v -race
14 changes: 7 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ module github.com/go-mojito/router-fasthttp
go 1.23

require (
github.com/fasthttp/router v1.5.2
github.com/go-mojito/mojito v0.0.17
github.com/fasthttp/router v1.5.3
github.com/go-mojito/mojito v0.0.19
github.com/infinytum/structures v0.0.3
github.com/valyala/fasthttp v1.55.0
github.com/valyala/fasthttp v1.57.0
)

require (
github.com/andybalholm/brotli v1.1.0 // indirect
github.com/andybalholm/brotli v1.1.1 // indirect
github.com/infinytum/injector v0.0.3 // indirect
github.com/infinytum/introspector v0.0.0-20221124203324-542f216aab81 // indirect
github.com/julienschmidt/httprouter v1.3.0 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/klauspost/compress v1.17.11 // indirect
github.com/mitchellh/hashstructure/v2 v2.0.2 // indirect
github.com/savsgio/gotils v0.0.0-20240704082632-aef3928b8a38 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/net v0.32.0 // indirect
golang.org/x/text v0.21.0 // indirect
)
30 changes: 16 additions & 14 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M=
github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY=
github.com/fasthttp/router v1.5.2 h1:ckJCCdV7hWkkrMeId3WfEhz+4Gyyf6QPwxi/RHIMZ6I=
github.com/fasthttp/router v1.5.2/go.mod h1:C8EY53ozOwpONyevc/V7Gr8pqnEjwnkFFqPo1alAGs0=
github.com/go-mojito/mojito v0.0.17 h1:fB1fUTB9t82609s4JkXG+WjOr6DLSUp41ClfmR1Olq0=
github.com/go-mojito/mojito v0.0.17/go.mod h1:0a3FnvQlV9BaJO268TptV7edAZftc/o8QSmBBOk3FUA=
github.com/andybalholm/brotli v1.1.1 h1:PR2pgnyFznKEugtsUo0xLdDop5SKXd5Qf5ysW+7XdTA=
github.com/andybalholm/brotli v1.1.1/go.mod h1:05ib4cKhjx3OQYUY22hTVd34Bc8upXjOLL2rKwwZBoA=
github.com/fasthttp/router v1.5.3 h1:BFWXqa3e4thRI3MgPKTNtz0Oiq6UYN2OsEtb+YQ5TMI=
github.com/fasthttp/router v1.5.3/go.mod h1:b864KkDIapOYh77AVG/SNkwfRZ6k6ecWvD+ZRXmP5pw=
github.com/go-mojito/mojito v0.0.19 h1:t2vowCYiSag7kXMXgk1E5hA1iXSNkbYI/DUh2s0ehYI=
github.com/go-mojito/mojito v0.0.19/go.mod h1:czTduo8DsH+/JGjvqCAAL6Zc8ppJ/3r8LJV6SPXGdEo=
github.com/infinytum/injector v0.0.3 h1:E7oj58MCr0emxPSNoRgGvAUdLwJP797vbD1mRSoOBQg=
github.com/infinytum/injector v0.0.3/go.mod h1:/8absiTs7Afl21cGagOLkXPrypVGZrOSkH4qu/IsP28=
github.com/infinytum/introspector v0.0.0-20221124203324-542f216aab81 h1:RG//Cr6nLKKWbdNDGavwFEuUInvzIk2wfmPG8LZBVaI=
Expand All @@ -12,17 +12,19 @@ github.com/infinytum/structures v0.0.3 h1:OackN0CC4OKpUwp9esX/VbzIbdql2t9pccPWA1
github.com/infinytum/structures v0.0.3/go.mod h1:4vDl7BamOX2fF0B+h2n/xGIorGv1u9ZQ9wgF6IW/Kc8=
github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U=
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=
github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
github.com/klauspost/compress v1.17.11 h1:In6xLpyWOi1+C7tXUUWv2ot1QvBjxevKAaI6IXrJmUc=
github.com/klauspost/compress v1.17.11/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0=
github.com/mitchellh/hashstructure/v2 v2.0.2 h1:vGKWl0YJqUNxE8d+h8f6NJLcCJrgbhC4NcD46KavDd4=
github.com/mitchellh/hashstructure/v2 v2.0.2/go.mod h1:MG3aRVU/N29oo/V/IhBX8GR/zz4kQkprJgF2EVszyDE=
github.com/savsgio/gotils v0.0.0-20240704082632-aef3928b8a38 h1:D0vL7YNisV2yqE55+q0lFuGse6U8lxlg7fYTctlT5Gc=
github.com/savsgio/gotils v0.0.0-20240704082632-aef3928b8a38/go.mod h1:sM7Mt7uEoCeFSCBM+qBrqvEo+/9vdmj19wzp3yzUhmg=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasthttp v1.55.0 h1:Zkefzgt6a7+bVKHnu/YaYSOPfNYNisSVBo/unVCf8k8=
github.com/valyala/fasthttp v1.55.0/go.mod h1:NkY9JtkrpPKmgwV3HTaS2HWaJss9RSIsRVfcxxoHiOM=
golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ=
golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE=
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
github.com/valyala/fasthttp v1.57.0 h1:Xw8SjWGEP/+wAAgyy5XTvgrWlOD1+TxbbvNADYCm1Tg=
github.com/valyala/fasthttp v1.57.0/go.mod h1:h6ZBaPRlzpZ6O3H5t2gEk1Qi33+TmLvfwgLLp0t9CpE=
github.com/xyproto/randomstring v1.0.5 h1:YtlWPoRdgMu3NZtP45drfy1GKoojuR7hmRcnhZqKjWU=
github.com/xyproto/randomstring v1.0.5/go.mod h1:rgmS5DeNXLivK7YprL0pY+lTuhNQW3iGxZ18UQApw/E=
golang.org/x/net v0.32.0 h1:ZqPmj8Kzc+Y6e0+skZsuACbx+wzMgo5MQsJh9Qd6aYI=
golang.org/x/net v0.32.0/go.mod h1:CwU0IoeOlnQQWJ6ioyFrfRuomB8GKF6KbYXZVyeXNfs=
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
22 changes: 11 additions & 11 deletions router.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,14 @@ func (r *Router) WithGroup(path string, callback func(group router.Group)) error
func (r *Router) WithRoute(method string, path string, handler interface{}) error {
h, err := router.GetOrCreateHandler(handler)
if err != nil {
log.Field("method", method).Field("path", path).Errorf("Error creating route handler: %s", err)
log.With("method", method, "path", path, "err", err).Error("Error creating route handler")
return err
}

// Chain router-wide middleware to the (new) handler
for _, middleware := range r.Middleware {
if err := h.AddMiddleware(middleware); err != nil {
log.Field("method", method).Field("path", path).Errorf("Failed to chain middleware to route: %s", err)
log.With("method", method, "path", path, "err", err).Error("Failed to chain middleware to route")
return err
}
}
Expand Down Expand Up @@ -130,7 +130,7 @@ func (r *Router) WithRoute(method string, path string, handler interface{}) erro
case http.MethodPatch:
r.Router.PATCH(path, r.withMojitoHandler(h))
default:
log.Field("method", method).Field("path", path).Error("The fasthttp router implementation unfortunately does not support this HTTP method")
log.With("method", method, "path", path).Error("The fasthttp router implementation unfortunately does not support this HTTP method")
return errors.New("the given HTTP method is not available on this router")
}
return r.Routes.Add(path, method, h)
Expand All @@ -139,7 +139,7 @@ func (r *Router) WithRoute(method string, path string, handler interface{}) erro
// WithNotFoundHandler will set the not found handler for the router
func (r *Router) WithNotFoundHandler(handler interface{}) error {
if h, err := router.GetOrCreateHandler(handler); err != nil {
log.Errorf("Error creating default handler: %s", err)
log.With("err", err).Error("Error creating not found handler")
return err
} else {
r.Router.NotFound = r.withMojitoHandler(h)
Expand All @@ -150,7 +150,7 @@ func (r *Router) WithNotFoundHandler(handler interface{}) error {
// WithMethodNotAllowedHandler will set the not allowed handler for the router
func (r *Router) WithMethodNotAllowedHandler(handler interface{}) error {
if h, err := router.GetOrCreateHandler(handler); err != nil {
log.Errorf("Error creating default handler: %s", err)
log.With("err", err).Error("Error creating not allowed handler")
return err
} else {
r.Router.MethodNotAllowed = r.withMojitoHandler(h)
Expand All @@ -160,13 +160,13 @@ func (r *Router) WithMethodNotAllowedHandler(handler interface{}) error {

// WithErrorHandler will set the error handler for the router
func (r *Router) WithErrorHandler(handler interface{}) error {
h, err := router.GetOrCreateHandler(handler)
if err != nil {
log.Errorf("Error creating error handler: %s", err)
if h, err := router.GetOrCreateHandler(handler); err != nil {
log.With("err", err).Error("Error creating error handler")
return err
} else {
r.ErrorHandler = h
r.Router.PanicHandler = r.onError
}
r.ErrorHandler = h
r.Router.PanicHandler = r.onError
return nil
}

Expand All @@ -175,7 +175,7 @@ func (r *Router) WithMiddleware(handler interface{}) error {
for _, rm := range r.Routes.ToMap() {
for _, h := range rm {
if err := h.AddMiddleware(handler); err != nil {
log.Error(err)
log.With("err", err).Error("Failed to chain middleware to route")
return err
}
}
Expand Down
26 changes: 13 additions & 13 deletions router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package fasthttp
import (
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"
"testing"
Expand Down Expand Up @@ -73,7 +73,7 @@ func Test_Router_GET(t *testing.T) {
if res.StatusCode != 200 {
t.Errorf(expectedStatus, 200, res.StatusCode)
}
if body, _ := ioutil.ReadAll(res.Body); string(body) != "OK" {
if body, _ := io.ReadAll(res.Body); string(body) != "OK" {
t.Errorf(expectedBody, body)
}
}
Expand All @@ -95,7 +95,7 @@ func Test_Router_GET_Params(t *testing.T) {
if res.StatusCode != 200 {
t.Errorf(expectedStatus, 200, res.StatusCode)
}
if body, _ := ioutil.ReadAll(res.Body); string(body) != "Hello world" {
if body, _ := io.ReadAll(res.Body); string(body) != "Hello world" {
t.Errorf(expectedBody, body)
}
}
Expand Down Expand Up @@ -130,7 +130,7 @@ func Test_Router_POST(t *testing.T) {
if res.StatusCode != 200 {
t.Errorf(expectedStatus, 200, res.StatusCode)
}
if body, _ := ioutil.ReadAll(res.Body); string(body) != "OK" {
if body, _ := io.ReadAll(res.Body); string(body) != "OK" {
t.Errorf(expectedBody, body)
}
}
Expand All @@ -149,7 +149,7 @@ func Test_Router_PUT(t *testing.T) {
if res.StatusCode != 200 {
t.Errorf(expectedStatus, 200, res.StatusCode)
}
if body, _ := ioutil.ReadAll(res.Body); string(body) != "OK" {
if body, _ := io.ReadAll(res.Body); string(body) != "OK" {
t.Errorf(expectedBody, body)
}
}
Expand All @@ -168,7 +168,7 @@ func Test_Router_DELETE(t *testing.T) {
if res.StatusCode != 200 {
t.Errorf(expectedStatus, 200, res.StatusCode)
}
if body, _ := ioutil.ReadAll(res.Body); string(body) != "OK" {
if body, _ := io.ReadAll(res.Body); string(body) != "OK" {
t.Errorf(expectedBody, body)
}
}
Expand All @@ -187,7 +187,7 @@ func Test_Router_CONNECT(t *testing.T) {
if res.StatusCode != 200 {
t.Errorf(expectedStatus, 200, res.StatusCode)
}
if body, _ := ioutil.ReadAll(res.Body); string(body) != "OK" {
if body, _ := io.ReadAll(res.Body); string(body) != "OK" {
t.Errorf(expectedBody, body)
}
}
Expand All @@ -206,7 +206,7 @@ func Test_Router_OPTIONS(t *testing.T) {
if res.StatusCode != 200 {
t.Errorf(expectedStatus, 200, res.StatusCode)
}
if body, _ := ioutil.ReadAll(res.Body); string(body) != "OK" {
if body, _ := io.ReadAll(res.Body); string(body) != "OK" {
t.Errorf(expectedBody, body)
}
}
Expand All @@ -225,7 +225,7 @@ func Test_Router_TRACE(t *testing.T) {
if res.StatusCode != 200 {
t.Errorf(expectedStatus, 200, res.StatusCode)
}
if body, _ := ioutil.ReadAll(res.Body); string(body) != "OK" {
if body, _ := io.ReadAll(res.Body); string(body) != "OK" {
t.Errorf(expectedBody, body)
}
}
Expand All @@ -244,7 +244,7 @@ func Test_Router_PATCH(t *testing.T) {
if res.StatusCode != 200 {
t.Errorf(expectedStatus, 200, res.StatusCode)
}
if body, _ := ioutil.ReadAll(res.Body); string(body) != "OK" {
if body, _ := io.ReadAll(res.Body); string(body) != "OK" {
t.Errorf(expectedBody, body)
}
}
Expand All @@ -266,7 +266,7 @@ func Test_Router_WithNotFoundHandler(t *testing.T) {
if res.StatusCode != 404 {
t.Errorf(expectedStatus, 404, res.StatusCode)
}
if body, _ := ioutil.ReadAll(res.Body); string(body) != "Not found" {
if body, _ := io.ReadAll(res.Body); string(body) != "Not found" {
t.Errorf(expectedBody, body)
}
}
Expand All @@ -289,7 +289,7 @@ func Test_Router_WithMethodNotAllowedHandler(t *testing.T) {
if res.StatusCode != 403 {
t.Errorf(expectedStatus, 403, res.StatusCode)
}
if body, _ := ioutil.ReadAll(res.Body); string(body) != "Method not allowed" {
if body, _ := io.ReadAll(res.Body); string(body) != "Method not allowed" {
t.Errorf(expectedBody, body)
}
}
Expand All @@ -314,7 +314,7 @@ func Test_Router_WithErrorHandler(t *testing.T) {
if res.StatusCode != 500 {
t.Errorf(expectedStatus, 500, res.StatusCode)
}
if body, _ := ioutil.ReadAll(res.Body); string(body) != "Internal Server Error" {
if body, _ := io.ReadAll(res.Body); string(body) != "Internal Server Error" {
t.Errorf(expectedBody, body)
}
}
Expand Down

0 comments on commit b5079eb

Please sign in to comment.