From 3ea5ee9e92f6822d3c76b5d599e3d40f8312fbe6 Mon Sep 17 00:00:00 2001 From: Wenbo Han Date: Sun, 8 Sep 2024 12:24:49 +0800 Subject: [PATCH] merge: v1.2.3 (#101) * merge: v1.2.3 * update go.mod --- go.mod | 42 ++++++----- go.sum | 43 ++++++++++- route.go | 12 +++ route_test.go | 204 +++++++++++++++++++++++++++++++++++++------------- 4 files changed, 225 insertions(+), 76 deletions(-) diff --git a/go.mod b/go.mod index 50a2ca5..df811ba 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,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.20240804133715-98a226e9dfb8 + github.com/goravel/framework v1.14.1-0.20240908041632-e37e7287f1b6 github.com/savioxavier/termlink v1.4.1 github.com/spf13/cast v1.7.0 github.com/stretchr/testify v1.9.0 @@ -35,15 +35,15 @@ require ( github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect github.com/catppuccin/go v0.2.0 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect - github.com/charmbracelet/bubbles v0.18.0 // indirect - github.com/charmbracelet/bubbletea v0.26.6 // indirect - github.com/charmbracelet/huh v0.5.2 // indirect - github.com/charmbracelet/huh/spinner v0.0.0-20240803000013-2eb851f67645 // indirect - github.com/charmbracelet/lipgloss v0.12.1 // indirect - github.com/charmbracelet/x/ansi v0.1.4 // indirect + github.com/charmbracelet/bubbles v0.20.0 // indirect + github.com/charmbracelet/bubbletea v1.1.0 // indirect + github.com/charmbracelet/huh v0.6.0 // indirect + github.com/charmbracelet/huh/spinner v0.0.0-20240906163306-a9285a0ef8a3 // 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.1.1 // 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 @@ -82,6 +82,7 @@ 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 @@ -107,8 +108,9 @@ require ( github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect github.com/muesli/cancelreader v0.2.2 // indirect - github.com/muesli/termenv v0.15.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 @@ -130,7 +132,7 @@ require ( github.com/spf13/viper v1.19.0 // indirect github.com/stretchr/objx v0.5.2 // indirect github.com/subosito/gotenv v1.6.0 // indirect - github.com/urfave/cli/v2 v2.27.3 // indirect + github.com/urfave/cli/v2 v2.27.4 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/tcplisten v1.0.0 // indirect github.com/xdg-go/pbkdf2 v1.0.0 // indirect @@ -148,20 +150,20 @@ require ( go.opentelemetry.io/otel/trace v1.24.0 // indirect go.uber.org/atomic v1.11.0 // indirect go.uber.org/multierr v1.9.0 // indirect - golang.org/x/crypto v0.25.0 // indirect - golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect + golang.org/x/crypto v0.27.0 // indirect + golang.org/x/exp v0.0.0-20240904232852-e7e105dedf7e // indirect golang.org/x/net v0.27.0 // indirect - golang.org/x/oauth2 v0.20.0 // indirect - golang.org/x/sync v0.7.0 // indirect - golang.org/x/sys v0.22.0 // indirect - golang.org/x/term v0.22.0 // indirect - golang.org/x/text v0.16.0 // indirect + golang.org/x/oauth2 v0.21.0 // indirect + golang.org/x/sync v0.8.0 // indirect + golang.org/x/sys v0.25.0 // indirect + golang.org/x/term v0.24.0 // indirect + golang.org/x/text v0.18.0 // indirect golang.org/x/time v0.5.0 // indirect google.golang.org/api v0.171.0 // indirect google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de // indirect - google.golang.org/genproto/googleapis/api v0.0.0-20240528184218-531527333157 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157 // indirect - google.golang.org/grpc v1.65.0 // 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 gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect diff --git a/go.sum b/go.sum index 17ad2ba..6ee88f4 100644 --- a/go.sum +++ b/go.sum @@ -115,6 +115,7 @@ github.com/aws/aws-sdk-go v1.49.6 h1:yNldzF5kzLBRvKlKz1S0bkvc2+04R1kt13KfBWQBfFA github.com/aws/aws-sdk-go v1.49.6/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk= github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k= github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8= +github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= github.com/bradfitz/gomemcache v0.0.0-20190913173617-a41fca850d0b/go.mod h1:H0wQNHz2YrLsuXOZozoeDmnHXkNCRmMW0gwFWDfEZDA= github.com/brianvoe/gofakeit/v6 v6.28.0 h1:Xib46XXuQfmlLS2EXRuJpqcw8St6qSZz75OUo0tgAW4= github.com/brianvoe/gofakeit/v6 v6.28.0/go.mod h1:Xj58BMSnFqcn/fAQeSK+/PLtC5kSb7FJIq4JyGa8vEs= @@ -135,16 +136,22 @@ github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UF github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/charmbracelet/bubbles v0.18.0 h1:PYv1A036luoBGroX6VWjQIE9Syf2Wby2oOl/39KLfy0= github.com/charmbracelet/bubbles v0.18.0/go.mod h1:08qhZhtIwzgrtBjAcJnij1t1H0ZRjwHyGsy6AL11PSw= +github.com/charmbracelet/bubbles v0.20.0/go.mod h1:39slydyswPy+uVOHZ5x/GjwVAFkCsV8IIVy+4MhzwwU= github.com/charmbracelet/bubbletea v0.26.6 h1:zTCWSuST+3yZYZnVSvbXwKOPRSNZceVeqpzOLN2zq1s= github.com/charmbracelet/bubbletea v0.26.6/go.mod h1:dz8CWPlfCCGLFbBlTY4N7bjLiyOGDJEnd2Muu7pOWhk= +github.com/charmbracelet/bubbletea v1.1.0/go.mod h1:9Ogk0HrdbHolIKHdjfFpyXJmiCzGwy+FesYkZr7hYU4= github.com/charmbracelet/huh v0.5.2 h1:ofeNkJ4iaFnzv46Njhx896DzLUe/j0L2QAf8znwzX4c= github.com/charmbracelet/huh v0.5.2/go.mod h1:Sf7dY0oAn6N/e3sXJFtFX9hdQLrUdO3z7AYollG9bAM= +github.com/charmbracelet/huh v0.6.0/go.mod h1:GGNKeWCeNzKpEOh/OJD8WBwTQjV3prFAtQPpLv+AVwU= github.com/charmbracelet/huh/spinner v0.0.0-20240803000013-2eb851f67645 h1:lpAqYjFpvhDyUjzQpRNUC+jrEgv6nT7gltkUZSpTPHA= github.com/charmbracelet/huh/spinner v0.0.0-20240803000013-2eb851f67645/go.mod h1:9VssyY5pUozMRmDYlLYV20QMMcA2sHg3qnaB6PvdIm8= +github.com/charmbracelet/huh/spinner v0.0.0-20240906163306-a9285a0ef8a3/go.mod h1:/dHGy3eS2ikDSO71IhslBdBGvrknQ+ze/VDiNdIxocw= github.com/charmbracelet/lipgloss v0.12.1 h1:/gmzszl+pedQpjCOH+wFkZr/N90Snz40J/NR7A0zQcs= github.com/charmbracelet/lipgloss v0.12.1/go.mod h1:V2CiwIuhx9S1S1ZlADfOj9HmxeMAORuz5izHb0zGbB8= +github.com/charmbracelet/lipgloss v0.13.0/go.mod h1:nw4zy0SBX/F/eAO1cWdcvy6qnkDUxr8Lw7dvFrAIbbY= github.com/charmbracelet/x/ansi v0.1.4 h1:IEU3D6+dWwPSgZ6HBH+v6oUuZ/nVawMiWj5831KfiLM= github.com/charmbracelet/x/ansi v0.1.4/go.mod h1:dk73KoMTT5AX5BsX0KrqhsTqAnhZZoCBjs7dGWp4Ktw= +github.com/charmbracelet/x/ansi v0.2.3/go.mod h1:dk73KoMTT5AX5BsX0KrqhsTqAnhZZoCBjs7dGWp4Ktw= github.com/charmbracelet/x/exp/strings v0.0.0-20240722160745-212f7b056ed0 h1:qko3AQ4gK1MTS/de7F5hPGx6/k1u0w4TeYmBFwzYVP4= github.com/charmbracelet/x/exp/strings v0.0.0-20240722160745-212f7b056ed0/go.mod h1:pBhA0ybfXv6hDjQUZ7hk1lVxBiUbupdw5R31yPUViVQ= github.com/charmbracelet/x/exp/term v0.0.0-20240524151031-ff83003bf67a h1:k/s6UoOSVynWiw7PlclyGO2VdVs5ZLbMIHiGp4shFZE= @@ -153,6 +160,7 @@ github.com/charmbracelet/x/input v0.1.3 h1:oy4TMhyGQsYs/WWJwu1ELUMFnjiUAXwtDf048 github.com/charmbracelet/x/input v0.1.3/go.mod h1:1gaCOyw1KI9e2j00j/BBZ4ErzRZqa05w0Ghn83yIhKU= github.com/charmbracelet/x/term v0.1.1 h1:3cosVAiPOig+EV4X9U+3LDgtwwAoEzJjNdwbXDjF6yI= github.com/charmbracelet/x/term v0.1.1/go.mod h1:wB1fHt5ECsu3mXYusyzcngVWWlu1KKUmmLhfgr/Flxw= +github.com/charmbracelet/x/term v0.2.0/go.mod h1:GVxgxAbjUrmpvIINHIQnJJKpMlHiZ4cktEQCN6GWyF0= github.com/charmbracelet/x/windows v0.1.2 h1:Iumiwq2G+BRmgoayww/qfcvof7W/3uLoelhxojXlRWg= github.com/charmbracelet/x/windows v0.1.2/go.mod h1:GLEO/l+lizvFDBPLIOk+49gdX49L9YWMB5t+DZd0jkQ= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= @@ -213,6 +221,8 @@ github.com/glebarez/sqlite v1.11.0/go.mod h1:h8/o8j5wiAsqSPoWELDUdJXhjAhsVliSn7b github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= +github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY= +github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ= github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= @@ -381,10 +391,14 @@ github.com/gookit/validate v1.5.2 h1:i5I2OQ7WYHFRPRATGu9QarR9snnNHydvwSuHXaRWAV0 github.com/gookit/validate v1.5.2/go.mod h1:yuPy2WwDlwGRa06fFJ5XIO8QEwhRnTC2LmxmBa5SE14= github.com/goravel/file-rotatelogs/v2 v2.4.2 h1:g68AzbePXcm0V2CpUMc9j4qVzcDn7+7aoWSjZ51C0m4= github.com/goravel/file-rotatelogs/v2 v2.4.2/go.mod h1:23VuSW8cBS4ax5cmbV+5AaiLpq25b8UJ96IhbAkdo8I= -github.com/goravel/framework v1.14.1-0.20240804133715-98a226e9dfb8 h1:3uZs9BMhOIGleWkyUJaH1Hwg03z+nF/osduSgFQD3qY= -github.com/goravel/framework v1.14.1-0.20240804133715-98a226e9dfb8/go.mod h1:uXY1t6lpuPtSM27aKNlib03OCG40xQcw4JbKcGlvz2k= +github.com/goravel/framework v1.14.1-0.20240908041632-e37e7287f1b6 h1:K5+sd6pgPYWmmGkKlA4poz1aTdpfNexnOukHDKpCdaU= +github.com/goravel/framework v1.14.1-0.20240908041632-e37e7287f1b6/go.mod h1:vM1HCnaoR2/FX5jusTgWHFu29pfpYBN1KOi5BtHzKx8= +github.com/goravel/framework v1.14.5 h1:FItqxRGkBK0h/TIknF24TuMZCtBRaSr3DnQLEzhfvXc= +github.com/goravel/framework v1.14.5/go.mod h1:rScDXGQZdoVfyxemNPmijlz/2a+lWNOa4jTuak5GGVg= github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4= github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM= +github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 h1:UH//fgunKIs4JdUbpDl1VZCDaL56wXCB/5+wF6uHfaI= +github.com/grpc-ecosystem/go-grpc-middleware v1.4.0/go.mod h1:g5qyo/la0ALbONm6Vbp88Yd8NsDy6rZz+RcrMPxvld8= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I= github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= @@ -429,6 +443,7 @@ github.com/karrick/godirwalk v1.8.0/go.mod h1:H5KPZjojv4lE+QYImBI8xVtrBRgYrIVsaR github.com/karrick/godirwalk v1.10.3/go.mod h1:RoGL9dQei4vP9ilrpETWE8CLOZ1kiN0LhBygSwrAsHA= github.com/kelseyhightower/envconfig v1.4.0 h1:Im6hONhd3pLkfDFsbRgu68RDNkGF1r3dvMUtDTo2cv8= github.com/kelseyhightower/envconfig v1.4.0/go.mod h1:cccZRl6mQpaq41TPp5QxidR+Sa3axMbJDNb//FQX6Gg= +github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/klauspost/compress v1.9.5/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= @@ -491,6 +506,7 @@ github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELU github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo= github.com/muesli/termenv v0.15.2 h1:GohcuySI0QmI3wN8Ok9PtKGkgkFIk7y6Vpb5PvrY+Wo= github.com/muesli/termenv v0.15.2/go.mod h1:Epx+iuz8sNs7mNKhxzH4fWXGNpZwUaJKRS1noLXviQ8= +github.com/muesli/termenv v0.15.3-0.20240618155329-98d742f6907a/go.mod h1:hxSnBBYLK21Vtq/PHd0S2FYCxBXzBua8ov5s1RobyRQ= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= @@ -505,8 +521,11 @@ github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8 github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= github.com/opencontainers/image-spec v1.0.2 h1:9yCKha/T5XdGtO0q9Q9a6T5NUCsTn/DrBg0D7ufOcFM= github.com/opencontainers/image-spec v1.0.2/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0= +github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs= github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc= +github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc= +github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ= github.com/pelletier/go-toml v1.7.0/go.mod h1:vwGMzjaWMwyfHwgIBhI2YUM4fB6nL6lVAvS1LBMMhTE= github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM= github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs= @@ -608,6 +627,7 @@ github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhV github.com/urfave/cli v1.22.5/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/urfave/cli/v2 v2.27.3 h1:/POWahRmdh7uztQ3CYnaDddk0Rm90PyOgIxgW2rr41M= github.com/urfave/cli/v2 v2.27.3/go.mod h1:m4QzxcD2qpra4z7WhzEGn74WZLViBnMpb1ToCAKdGRQ= +github.com/urfave/cli/v2 v2.27.4/go.mod h1:m4QzxcD2qpra4z7WhzEGn74WZLViBnMpb1ToCAKdGRQ= 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= @@ -661,12 +681,16 @@ go.opentelemetry.io/otel/sdk v1.22.0 h1:6coWHw9xw7EfClIC/+O31R8IY3/+EiRFHevmHafB go.opentelemetry.io/otel/sdk v1.22.0/go.mod h1:iu7luyVGYovrRpe2fmj3CVKouQNdTOkxtLzPvPz1DOc= go.opentelemetry.io/otel/trace v1.24.0 h1:CsKnnL4dUAr/0llH9FKuc698G04IrpWV0MQA/Y1YELI= go.opentelemetry.io/otel/trace v1.24.0/go.mod h1:HPc3Xr/cOApsBI154IU0OI0HJexz+aw5uPdbs3UCjNU= +go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE= go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0= +go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A= go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A= go.uber.org/goleak v1.2.1/go.mod h1:qlT2yGI9QafXHhZZLxlSuNsMw3FFLxBr+tBRlmO1xH4= +go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI= go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ= +go.uber.org/zap v1.18.1/go.mod h1:xg/QME4nWcxGxrpdeYfq7UvYrLh66cuVKdrbD1XF/NI= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190422162423-af44ce270edf/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE= @@ -686,6 +710,7 @@ golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliY golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg= golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30= golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M= +golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -698,6 +723,7 @@ golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EH golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 h1:2dVuKD2vS7b0QIHQbpyTISPd0LeHDbnYEryqj5Q1ug8= golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY= +golang.org/x/exp v0.0.0-20240904232852-e7e105dedf7e/go.mod h1:akd2r19cwCdwSwWeIdzYQGa/EZZyqcOdwWiwj5L5eKQ= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= @@ -785,6 +811,7 @@ golang.org/x/oauth2 v0.0.0-20201208152858-08078c50e5b5/go.mod h1:KelEdhl1UZF7XfJ golang.org/x/oauth2 v0.0.0-20210113205817-d3ed898aa8a3/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.20.0 h1:4mQdhULixXKP1rwYBW0vAijoXnkTG0BLCDRzfe1idMo= golang.org/x/oauth2 v0.20.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= +golang.org/x/oauth2 v0.21.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -802,6 +829,7 @@ golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -851,6 +879,7 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211013075003-97ac67df715c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -865,6 +894,7 @@ golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI= golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= @@ -877,6 +907,7 @@ golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU= golang.org/x/term v0.16.0/go.mod h1:yn7UURbUtPyrVJPGPq404EukNFxcm/foM+bV/bfcDsY= golang.org/x/term v0.22.0 h1:BbsgPEJULsl2fV/AT3v15Mjva5yXKQDyKf+TbDz7QJk= golang.org/x/term v0.22.0/go.mod h1:F3qCibpT5AMpCRfhfT53vVJwhLtIVHhB9XDjfFvnMI4= +golang.org/x/term v0.24.0/go.mod h1:lOBK/LVxemqiMij05LGJ0tzNr8xlmwBRJ81PX6wVLH8= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -894,6 +925,7 @@ golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= +golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -919,6 +951,7 @@ golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgw golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191108193012-7d206e10da11/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191113191852-77e3bb0ad9e7/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191115202509-3a792d9c32b2/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= @@ -941,6 +974,7 @@ golang.org/x/tools v0.0.0-20200501065659-ab2804fb9c9d/go.mod h1:EkVYQZoAsY45+roY golang.org/x/tools v0.0.0-20200512131952-2bc93b1c0c88/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20200515010526-7d3b6ebf133d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20200618134242-20370b0cb4b2/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= @@ -950,6 +984,7 @@ golang.org/x/tools v0.0.0-20201201161351-ac6f37ff4c2a/go.mod h1:emZCQorbCU4vsT4f golang.org/x/tools v0.0.0-20201208233053-a543418bbed2/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20210108195828-e2f9c7f1fc8e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= @@ -1011,6 +1046,7 @@ google.golang.org/genproto v0.0.0-20200228133532-8c2c7df3a383/go.mod h1:55QSHmfG google.golang.org/genproto v0.0.0-20200305110556-506484158171/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= google.golang.org/genproto v0.0.0-20200312145019-da6875a35672/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= google.golang.org/genproto v0.0.0-20200331122359-1ee6d9798940/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200423170343-7949de9c1215/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= google.golang.org/genproto v0.0.0-20200430143042-b979b6f78d84/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= google.golang.org/genproto v0.0.0-20200511104702-f5ebc3bea380/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= google.golang.org/genproto v0.0.0-20200515170657-fc4c6c6a6587/go.mod h1:YsZOwe1myG/8QRHRsmBRE1LrgQY60beZKjly0O1fX9U= @@ -1030,8 +1066,10 @@ google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de h1:F6qOa9AZTYJXOUE google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de/go.mod h1:VUhTRKeHn9wwcdrk73nvdC9gF178Tzhmt/qyaFcPLSo= google.golang.org/genproto/googleapis/api v0.0.0-20240528184218-531527333157 h1:7whR9kGa5LUwFtpLm2ArCEejtnxlGeLbAyjFY8sGNFw= google.golang.org/genproto/googleapis/api v0.0.0-20240528184218-531527333157/go.mod h1:99sLkeliLXfdj2J75X3Ho+rrVCaJze0uwN7zDDkjPVU= +google.golang.org/genproto/googleapis/api v0.0.0-20240604185151-ef581f913117/go.mod h1:OimBR/bc1wPO9iV4NC2bpyjy3VnAwZh5EBPQdtaE5oo= google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157 h1:Zy9XzmMEflZ/MAaA7vNcoebnRAld7FsPW1EeBB7V0m8= google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157/go.mod h1:EfXuqaE1J41VCDicxHzUDm+8rk+7ZdXzHV0IhO/I6s0= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240604185151-ef581f913117/go.mod h1:EfXuqaE1J41VCDicxHzUDm+8rk+7ZdXzHV0IhO/I6s0= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= @@ -1050,6 +1088,7 @@ google.golang.org/grpc v1.34.0/go.mod h1:WotjhfgOW/POjDeRt8vscBtXq+2VjORFy659qA5 google.golang.org/grpc v1.35.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= google.golang.org/grpc v1.65.0 h1:bs/cUb4lp1G5iImFFd3u5ixQzweKizoZJAwBNLR42lc= google.golang.org/grpc v1.65.0/go.mod h1:WgYC2ypjlB0EiQi6wdKixMqukr6lBc0Vo+oOgjrM5ZQ= +google.golang.org/grpc v1.66.0/go.mod h1:s3/l6xSSCURdVfAnL+TqCNMyTDAGN6+lZeVxnZR128Y= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= diff --git a/route.go b/route.go index 789af9d..2c27243 100644 --- a/route.go +++ b/route.go @@ -1,6 +1,7 @@ package fiber import ( + "context" "errors" "fmt" "net/http" @@ -184,6 +185,17 @@ func (r *Route) RunTLSWithCert(host, certFile, keyFile string) error { return r.instance.ListenTLS(host, certFile, keyFile) } +// Shutdown gracefully shuts down the server +// Shutdown 优雅退出HTTP Server +func (r *Route) Shutdown(ctx ...context.Context) error { + c := context.Background() + if len(ctx) > 0 { + c = ctx[0] + } + + return r.instance.ShutdownWithContext(c) +} + // ServeHTTP serve http request (Not support) // ServeHTTP 服务 HTTP 请求 (不支持) func (r *Route) ServeHTTP(writer http.ResponseWriter, request *http.Request) { diff --git a/route_test.go b/route_test.go index 6ebffb8..a89cf9b 100644 --- a/route_test.go +++ b/route_test.go @@ -3,9 +3,12 @@ package fiber import ( "crypto/tls" "errors" + "fmt" "io" "mime/multipart" "net/http" + "sync" + "sync/atomic" "testing" "time" @@ -18,10 +21,10 @@ import ( ) func TestFallback(t *testing.T) { - mockConfig := &configmocks.Config{} - mockConfig.On("GetBool", "http.drivers.fiber.prefork", false).Return(false).Once() - mockConfig.On("GetInt", "http.drivers.fiber.body_limit", 4096).Return(4096).Once() - mockConfig.On("GetInt", "http.drivers.fiber.header_limit", 4096).Return(4096).Once() + mockConfig := configmocks.NewConfig(t) + mockConfig.EXPECT().GetBool("http.drivers.fiber.prefork", false).Return(false).Once() + mockConfig.EXPECT().GetInt("http.drivers.fiber.body_limit", 4096).Return(4096).Once() + mockConfig.EXPECT().GetInt("http.drivers.fiber.header_limit", 4096).Return(4096).Once() ConfigFacade = mockConfig route, err := NewRoute(mockConfig, nil) @@ -41,8 +44,6 @@ func TestFallback(t *testing.T) { body, err := io.ReadAll(resp.Body) assert.Nil(t, err) assert.Equal(t, "not found", string(body)) - - mockConfig.AssertExpectations(t) } func TestRun(t *testing.T) { @@ -62,8 +63,8 @@ func TestRun(t *testing.T) { { name: "error when default port is empty", setup: func(host string, port string) error { - mockConfig.On("GetString", "http.host").Return(host).Once() - mockConfig.On("GetString", "http.port").Return(port).Once() + mockConfig.EXPECT().GetString("http.host").Return(host).Once() + mockConfig.EXPECT().GetString("http.port").Return(port).Once() go func() { assert.EqualError(t, route.Run(), "port can't be empty") @@ -77,9 +78,9 @@ func TestRun(t *testing.T) { { name: "use default host", setup: func(host string, port string) error { - mockConfig.On("GetBool", "app.debug").Return(true).Once() - mockConfig.On("GetString", "http.host").Return(host).Once() - mockConfig.On("GetString", "http.port").Return(port).Once() + mockConfig.EXPECT().GetBool("app.debug").Return(true).Once() + mockConfig.EXPECT().GetString("http.host").Return(host).Once() + mockConfig.EXPECT().GetString("http.port").Return(port).Once() go func() { assert.Nil(t, route.Run()) @@ -95,7 +96,7 @@ func TestRun(t *testing.T) { { name: "use custom host", setup: func(host string, port string) error { - mockConfig.On("GetBool", "app.debug").Return(true).Once() + mockConfig.EXPECT().GetBool("app.debug").Return(true).Once() go func() { assert.Nil(t, route.Run(host)) @@ -109,10 +110,10 @@ func TestRun(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { - mockConfig = &configmocks.Config{} - mockConfig.On("GetBool", "http.drivers.fiber.prefork", false).Return(false).Once() - mockConfig.On("GetInt", "http.drivers.fiber.body_limit", 4096).Return(4096).Once() - mockConfig.On("GetInt", "http.drivers.fiber.header_limit", 4096).Return(4096).Once() + mockConfig = configmocks.NewConfig(t) + mockConfig.EXPECT().GetBool("http.drivers.fiber.prefork", false).Return(false).Once() + mockConfig.EXPECT().GetInt("http.drivers.fiber.body_limit", 4096).Return(4096).Once() + mockConfig.EXPECT().GetInt("http.drivers.fiber.header_limit", 4096).Return(4096).Once() ConfigFacade = mockConfig route, err = NewRoute(mockConfig, nil) @@ -137,8 +138,6 @@ func TestRun(t *testing.T) { assert.Nil(t, err) assert.Equal(t, "{\"Hello\":\"Goravel\"}", string(body)) } - - mockConfig.AssertExpectations(t) }) } } @@ -160,8 +159,8 @@ func TestRunTLS(t *testing.T) { { name: "error when default port is empty", setup: func(host string, port string) error { - mockConfig.On("GetString", "http.tls.host").Return(host).Once() - mockConfig.On("GetString", "http.tls.port").Return(port).Once() + mockConfig.EXPECT().GetString("http.tls.host").Return(host).Once() + mockConfig.EXPECT().GetString("http.tls.port").Return(port).Once() go func() { assert.EqualError(t, route.RunTLS(), "port can't be empty") @@ -175,11 +174,11 @@ func TestRunTLS(t *testing.T) { { name: "use default host", setup: func(host string, port string) error { - mockConfig.On("GetBool", "app.debug").Return(true).Once() - mockConfig.On("GetString", "http.tls.host").Return(host).Once() - mockConfig.On("GetString", "http.tls.port").Return(port).Once() - mockConfig.On("GetString", "http.tls.ssl.cert").Return("test_ca.crt").Once() - mockConfig.On("GetString", "http.tls.ssl.key").Return("test_ca.key").Once() + mockConfig.EXPECT().GetBool("app.debug").Return(true).Once() + mockConfig.EXPECT().GetString("http.tls.host").Return(host).Once() + mockConfig.EXPECT().GetString("http.tls.port").Return(port).Once() + mockConfig.EXPECT().GetString("http.tls.ssl.cert").Return("test_ca.crt").Once() + mockConfig.EXPECT().GetString("http.tls.ssl.key").Return("test_ca.key").Once() go func() { assert.Nil(t, route.RunTLS()) @@ -193,9 +192,9 @@ func TestRunTLS(t *testing.T) { { name: "use custom host", setup: func(host string, port string) error { - mockConfig.On("GetBool", "app.debug").Return(true).Once() - mockConfig.On("GetString", "http.tls.ssl.cert").Return("test_ca.crt").Once() - mockConfig.On("GetString", "http.tls.ssl.key").Return("test_ca.key").Once() + mockConfig.EXPECT().GetBool("app.debug").Return(true).Once() + mockConfig.EXPECT().GetString("http.tls.ssl.cert").Return("test_ca.crt").Once() + mockConfig.EXPECT().GetString("http.tls.ssl.key").Return("test_ca.key").Once() go func() { assert.Nil(t, route.RunTLS(host)) @@ -209,10 +208,10 @@ func TestRunTLS(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { - mockConfig = &configmocks.Config{} - mockConfig.On("GetBool", "http.drivers.fiber.prefork", false).Return(false).Once() - mockConfig.On("GetInt", "http.drivers.fiber.body_limit", 4096).Return(4096).Once() - mockConfig.On("GetInt", "http.drivers.fiber.header_limit", 4096).Return(4096).Once() + mockConfig = configmocks.NewConfig(t) + mockConfig.EXPECT().GetBool("http.drivers.fiber.prefork", false).Return(false).Once() + mockConfig.EXPECT().GetInt("http.drivers.fiber.body_limit", 4096).Return(4096).Once() + mockConfig.EXPECT().GetInt("http.drivers.fiber.header_limit", 4096).Return(4096).Once() ConfigFacade = mockConfig route, err = NewRoute(mockConfig, nil) @@ -242,7 +241,6 @@ func TestRunTLS(t *testing.T) { assert.Equal(t, "{\"Hello\":\"Goravel\"}", string(body)) } - mockConfig.AssertExpectations(t) }) } } @@ -274,7 +272,7 @@ func TestRunTLSWithCert(t *testing.T) { { name: "use default host", setup: func(host string) error { - mockConfig.On("GetBool", "app.debug").Return(true).Once() + mockConfig.EXPECT().GetBool("app.debug").Return(true).Once() go func() { assert.Nil(t, route.RunTLSWithCert(host, "test_ca.crt", "test_ca.key")) @@ -287,7 +285,7 @@ func TestRunTLSWithCert(t *testing.T) { { name: "use custom host", setup: func(host string) error { - mockConfig.On("GetBool", "app.debug").Return(true).Once() + mockConfig.EXPECT().GetBool("app.debug").Return(true).Once() go func() { assert.Nil(t, route.RunTLSWithCert(host, "test_ca.crt", "test_ca.key")) @@ -301,10 +299,10 @@ func TestRunTLSWithCert(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { - mockConfig = &configmocks.Config{} - mockConfig.On("GetBool", "http.drivers.fiber.prefork", false).Return(false).Once() - mockConfig.On("GetInt", "http.drivers.fiber.body_limit", 4096).Return(4096).Once() - mockConfig.On("GetInt", "http.drivers.fiber.header_limit", 4096).Return(4096).Once() + mockConfig = configmocks.NewConfig(t) + mockConfig.EXPECT().GetBool("http.drivers.fiber.prefork", false).Return(false).Once() + mockConfig.EXPECT().GetInt("http.drivers.fiber.body_limit", 4096).Return(4096).Once() + mockConfig.EXPECT().GetInt("http.drivers.fiber.header_limit", 4096).Return(4096).Once() ConfigFacade = mockConfig route, err = NewRoute(mockConfig, nil) @@ -330,7 +328,6 @@ func TestRunTLSWithCert(t *testing.T) { assert.Equal(t, "{\"Hello\":\"Goravel\"}", string(body)) } - mockConfig.AssertExpectations(t) }) } } @@ -349,9 +346,9 @@ func TestNewRoute(t *testing.T) { { name: "parameters is nil", setup: func() { - mockConfig.On("GetBool", "http.drivers.fiber.prefork", false).Return(false).Once() - mockConfig.On("GetInt", "http.drivers.fiber.body_limit", 4096).Return(4096).Once() - mockConfig.On("GetInt", "http.drivers.fiber.header_limit", 4096).Return(4096).Once() + mockConfig.EXPECT().GetBool("http.drivers.fiber.prefork", false).Return(false).Once() + mockConfig.EXPECT().GetInt("http.drivers.fiber.body_limit", 4096).Return(4096).Once() + mockConfig.EXPECT().GetInt("http.drivers.fiber.header_limit", 4096).Return(4096).Once() }, expectTemplate: nil, }, @@ -359,10 +356,10 @@ func TestNewRoute(t *testing.T) { name: "template is instance", parameters: map[string]any{"driver": "fiber"}, setup: func() { - mockConfig.On("GetBool", "http.drivers.fiber.prefork", false).Return(false).Once() - mockConfig.On("GetInt", "http.drivers.fiber.body_limit", 4096).Return(4096).Once() - mockConfig.On("GetInt", "http.drivers.fiber.header_limit", 4096).Return(4096).Once() - mockConfig.On("Get", "http.drivers.fiber.template").Return(template).Once() + mockConfig.EXPECT().GetBool("http.drivers.fiber.prefork", false).Return(false).Once() + mockConfig.EXPECT().GetInt("http.drivers.fiber.body_limit", 4096).Return(4096).Once() + mockConfig.EXPECT().GetInt("http.drivers.fiber.header_limit", 4096).Return(4096).Once() + mockConfig.EXPECT().Get("http.drivers.fiber.template").Return(template).Once() }, expectTemplate: template, }, @@ -370,10 +367,10 @@ func TestNewRoute(t *testing.T) { name: "template is callback and returns success", parameters: map[string]any{"driver": "fiber"}, setup: func() { - mockConfig.On("GetBool", "http.drivers.fiber.prefork", false).Return(false).Once() - mockConfig.On("GetInt", "http.drivers.fiber.body_limit", 4096).Return(4096).Once() - mockConfig.On("GetInt", "http.drivers.fiber.header_limit", 4096).Return(4096).Once() - mockConfig.On("Get", "http.drivers.fiber.template").Return(func() (fiber.Views, error) { + mockConfig.EXPECT().GetBool("http.drivers.fiber.prefork", false).Return(false).Once() + mockConfig.EXPECT().GetInt("http.drivers.fiber.body_limit", 4096).Return(4096).Once() + mockConfig.EXPECT().GetInt("http.drivers.fiber.header_limit", 4096).Return(4096).Once() + mockConfig.EXPECT().Get("http.drivers.fiber.template").Return(func() (fiber.Views, error) { return template, nil }).Twice() }, @@ -383,7 +380,7 @@ func TestNewRoute(t *testing.T) { name: "template is callback and returns error", parameters: map[string]any{"driver": "fiber"}, setup: func() { - mockConfig.On("Get", "http.drivers.fiber.template").Return(func() (fiber.Views, error) { + mockConfig.EXPECT().Get("http.drivers.fiber.template").Return(func() (fiber.Views, error) { return nil, errors.New("error") }).Twice() }, @@ -393,7 +390,7 @@ func TestNewRoute(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { - mockConfig = &configmocks.Config{} + mockConfig = configmocks.NewConfig(t) test.setup() route, err := NewRoute(mockConfig, test.parameters) assert.Equal(t, test.expectError, err) @@ -401,11 +398,110 @@ func TestNewRoute(t *testing.T) { assert.IsType(t, test.expectTemplate, route.instance.Config().Views) } - mockConfig.AssertExpectations(t) }) } } +func TestShutdown(t *testing.T) { + var ( + err error + mockConfig *configmocks.Config + route *Route + count atomic.Int64 + host = "127.0.0.1" + port = "6789" + addr = fmt.Sprintf("http://%s:%s", host, port) + ) + + tests := []struct { + name string + setup func() error + }{ + { + name: "no new requests will be accepted after shutdown", + setup: func() error { + go func() { + assert.Nil(t, route.Run()) + }() + + time.Sleep(1 * time.Second) + + assertHttpNormal(t, addr, true) + + assert.Nil(t, route.Shutdown()) + + assertHttpNormal(t, addr, false) + return nil + }, + }, + { + name: "Ensure that received requests are processed", + setup: func() error { + go func() { + assert.Nil(t, route.Run()) + }() + + time.Sleep(1 * time.Second) + + wg := sync.WaitGroup{} + count.Store(0) + for i := 0; i < 3; i++ { + wg.Add(1) + go func() { + defer wg.Done() + assertHttpNormal(t, addr, true) + }() + } + time.Sleep(100 * time.Millisecond) + assert.Nil(t, route.Shutdown()) + assertHttpNormal(t, addr, false) + wg.Wait() + assert.Equal(t, count.Load(), int64(3)) + return nil + }, + }, + } + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + mockConfig = configmocks.NewConfig(t) + mockConfig.EXPECT().GetBool("app.debug").Return(true) + mockConfig.EXPECT().GetBool("http.drivers.fiber.prefork", false).Return(false).Once() + mockConfig.EXPECT().GetInt("http.drivers.fiber.header_limit", 4096).Return(4096).Once() + mockConfig.EXPECT().GetInt("http.drivers.fiber.body_limit", 4096).Return(4096).Once() + mockConfig.EXPECT().GetString("http.host").Return(host).Once() + mockConfig.EXPECT().GetString("http.port").Return(port).Once() + route, err = NewRoute(mockConfig, nil) + assert.Nil(t, err) + route.Get("/", func(ctx contractshttp.Context) contractshttp.Response { + time.Sleep(time.Second) + defer count.Add(1) + return ctx.Response().Success().String("Goravel") + }) + if err := test.setup(); err == nil { + assert.Nil(t, err) + } + }) + } +} + +func assertHttpNormal(t *testing.T, addr string, expectNormal bool) { + resp, err := http.DefaultClient.Get(addr) + if !expectNormal { + assert.NotNil(t, err) + assert.Nil(t, resp) + } else { + assert.Nil(t, err) + assert.NotNil(t, resp) + if resp != nil { + assert.Equal(t, resp.StatusCode, http.StatusOK) + body, err := io.ReadAll(resp.Body) + assert.Nil(t, err) + assert.Equal(t, string(body), "Goravel") + } + } +} + type CreateUser struct { Name string `form:"name" json:"name"` }