Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge: v1.2.4 #107

Merged
merged 6 commits into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/check-pr-title.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: Check PR Title
on:
pull_request:
jobs:
check:
uses: goravel/.github/.github/workflows/check_pr_title.yml@master
secrets: inherit
17 changes: 2 additions & 15 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,5 @@ on:
pull_request:
jobs:
codecov:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: 'stable'
- name: Install dependencies
run: go mod tidy
- name: Run tests with coverage
run: go test -v -coverprofile="coverage.out" ./...
- name: Upload coverage report to Codecov
uses: codecov/codecov-action@v4
with:
file: ./coverage.out
token: ${{ secrets.CODECOV }}
uses: goravel/.github/.github/workflows/codecov.yml@master
secrets: inherit
24 changes: 2 additions & 22 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,5 @@ permissions:
contents: read
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: 'stable'
cache: false
- name: go mod pakcage cache
uses: actions/cache@v4
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('go.mod') }}
- name: Install dependencies
run: go mod tidy
- name: Lint
uses: golangci/golangci-lint-action@v6
with:
skip-cache: true
skip-pkg-cache: true
skip-build-cache: true
version: latest
args: --timeout=30m ./...
uses: goravel/.github/.github/workflows/lint.yml@master
secrets: inherit
11 changes: 0 additions & 11 deletions .github/workflows/pr-check-title.yml

This file was deleted.

31 changes: 3 additions & 28 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,6 @@ on:
- master
pull_request:
jobs:
ubuntu:
strategy:
matrix:
go: [ "1.21", "1.22" ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go }}
- name: Install dependencies
run: go mod tidy
- name: Run tests
run: go test ./...
windows:
strategy:
matrix:
go: [ "1.21", "1.22" ]
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go }}
- name: Install dependencies
run: go mod tidy
- name: Run tests
run: go test ./... -short
test:
uses: goravel/.github/.github/workflows/test.yml@master
secrets: inherit
12 changes: 3 additions & 9 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ type Context struct {
request http.ContextRequest
}

type ctxKey string

func NewContext(ctx *fiber.Ctx) http.Context {
return &Context{instance: ctx}
}
Expand All @@ -39,8 +37,8 @@ func (c *Context) Response() http.ContextResponse {
return NewContextResponse(c.instance, &ResponseOrigin{Ctx: c.instance})
}

func (c *Context) WithValue(key string, value any) {
ctx := context.WithValue(c.instance.UserContext(), ctxKey(key), value)
func (c *Context) WithValue(key any, value any) {
ctx := context.WithValue(c.instance.UserContext(), key, value)
c.instance.SetUserContext(ctx)
}

Expand All @@ -61,11 +59,7 @@ func (c *Context) Err() error {
}

func (c *Context) Value(key any) any {
if keyStr, ok := key.(string); ok {
return c.instance.UserContext().Value(ctxKey(keyStr))
}

return nil
return c.instance.UserContext().Value(key)
}

func (c *Context) Instance() *fiber.Ctx {
Expand Down
20 changes: 18 additions & 2 deletions context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,26 @@ import (
)

func TestContext(t *testing.T) {
type customKeyType struct{}
var customKey customKeyType

httpCtx := Background()
httpCtx.WithValue("Hello", "world")
httpCtx.WithValue("Hi", "Goravel")
httpCtx.WithValue(customKey, "halo")
httpCtx.WithValue(1, "one")
httpCtx.WithValue(2.2, "two point two")

assert.Equal(t, "world", httpCtx.Value("Hello"))
assert.Equal(t, "Goravel", httpCtx.Value("Hi"))
assert.Equal(t, "halo", httpCtx.Value(customKey))
assert.Equal(t, "one", httpCtx.Value(1))
assert.Equal(t, "two point two", httpCtx.Value(2.2))

assert.Equal(t, httpCtx.Value("Hello").(string), "world")
assert.Equal(t, httpCtx.Value("Hi").(string), "Goravel")
ctx := httpCtx.Context()
assert.Equal(t, "world", ctx.Value("Hello"))
assert.Equal(t, "Goravel", ctx.Value("Hi"))
assert.Equal(t, "halo", ctx.Value(customKey))
assert.Equal(t, "one", ctx.Value(1))
assert.Equal(t, "two point two", ctx.Value(2.2))
}
34 changes: 16 additions & 18 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
module github.com/goravel/fiber

go 1.21
go 1.22

toolchain go1.22.7

require (
github.com/gofiber/fiber/v2 v2.52.5
github.com/gofiber/template/html/v2 v2.1.2
github.com/gookit/validate v1.5.2
github.com/goravel/framework v1.14.1-0.20240908041632-e37e7287f1b6
github.com/goravel/framework v1.14.1-0.20240921081212-2ba57341a0d8
github.com/savioxavier/termlink v1.4.1
github.com/spf13/cast v1.7.0
github.com/stretchr/testify v1.9.0
Expand Down Expand Up @@ -36,15 +38,13 @@ require (
github.com/catppuccin/go v0.2.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/charmbracelet/bubbles v0.20.0 // indirect
github.com/charmbracelet/bubbletea v1.1.0 // indirect
github.com/charmbracelet/bubbletea v1.1.1 // indirect
github.com/charmbracelet/huh v0.6.0 // indirect
github.com/charmbracelet/huh/spinner v0.0.0-20240906163306-a9285a0ef8a3 // indirect
github.com/charmbracelet/huh/spinner v0.0.0-20240917123815-c9b2c9cdb7b6 // indirect
github.com/charmbracelet/lipgloss v0.13.0 // indirect
github.com/charmbracelet/x/ansi v0.2.3 // indirect
github.com/charmbracelet/x/exp/strings v0.0.0-20240722160745-212f7b056ed0 // indirect
github.com/charmbracelet/x/input v0.1.3 // indirect
github.com/charmbracelet/x/term v0.2.0 // indirect
github.com/charmbracelet/x/windows v0.1.2 // indirect
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
Expand All @@ -56,7 +56,7 @@ require (
github.com/gabriel-vasile/mimetype v1.4.5 // indirect
github.com/glebarez/go-sqlite v1.22.0 // indirect
github.com/glebarez/sqlite v1.11.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-redsync/redsync/v4 v4.8.1 // indirect
github.com/go-sql-driver/mysql v1.8.1 // indirect
Expand All @@ -65,7 +65,7 @@ require (
github.com/gofiber/utils v1.1.0 // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
github.com/golang-jwt/jwt/v5 v5.2.1 // indirect
github.com/golang-migrate/migrate/v4 v4.17.1 // indirect
github.com/golang-migrate/migrate/v4 v4.18.0 // indirect
github.com/golang-module/carbon/v2 v2.3.12 // indirect
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // indirect
github.com/golang-sql/sqlexp v0.1.0 // indirect
Expand All @@ -82,7 +82,6 @@ require (
github.com/gookit/filter v1.2.1 // indirect
github.com/gookit/goutil v0.6.15 // indirect
github.com/goravel/file-rotatelogs/v2 v2.4.2 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
Expand Down Expand Up @@ -110,7 +109,6 @@ require (
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/termenv v0.15.3-0.20240618155329-98d742f6907a // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
Expand Down Expand Up @@ -144,10 +142,10 @@ require (
go.mongodb.org/mongo-driver v1.7.5 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.52.0 // indirect
go.opentelemetry.io/otel v1.29.0 // indirect
go.opentelemetry.io/otel/metric v1.29.0 // indirect
go.opentelemetry.io/otel/trace v1.29.0 // indirect
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/crypto v0.27.0 // indirect
Expand All @@ -163,16 +161,16 @@ require (
google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240604185151-ef581f913117 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240604185151-ef581f913117 // indirect
google.golang.org/grpc v1.66.0 // indirect
google.golang.org/protobuf v1.34.1 // indirect
google.golang.org/grpc v1.66.2 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gorm.io/driver/mysql v1.5.7 // indirect
gorm.io/driver/postgres v1.5.9 // indirect
gorm.io/driver/sqlserver v1.5.3 // indirect
gorm.io/gorm v1.25.11 // indirect
gorm.io/plugin/dbresolver v1.5.2 // indirect
gorm.io/gorm v1.25.12 // indirect
gorm.io/plugin/dbresolver v1.5.3 // indirect
modernc.org/libc v1.37.6 // indirect
modernc.org/mathutil v1.6.0 // indirect
modernc.org/memory v1.7.2 // indirect
Expand Down
Loading
Loading