Skip to content

Commit

Permalink
fix: link (#141)
Browse files Browse the repository at this point in the history
* upgrade: framework v1.15.1 (#137)

* fix: link (#139)

* fix: link

* fix test
  • Loading branch information
hwbrzzl authored Jan 1, 2025
1 parent 5c495d9 commit 3115a42
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 30 deletions.
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ require (
github.com/gofiber/fiber/v2 v2.52.6
github.com/gofiber/template/html/v2 v2.1.2
github.com/gookit/validate v1.5.4
github.com/goravel/framework v1.15.1
github.com/savioxavier/termlink v1.4.1
github.com/goravel/framework v1.15.2
github.com/spf13/cast v1.7.1
github.com/stretchr/testify v1.10.0
github.com/valyala/fasthttp v1.58.0
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,8 @@ github.com/gookit/validate v1.5.4 h1:nwBo6vULnVUeNFCOde6RKFRbOCKJXVMnWR0ghedacLg
github.com/gookit/validate v1.5.4/go.mod h1:p9sRPfpvYB4vXICBpEPzv8FoAky+XhUOhWQghgmmat4=
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.15.1 h1:9K5Vf51+0YIQbLMd1+hk0L7LDBMaAmeLlQnoHJu6wow=
github.com/goravel/framework v1.15.1/go.mod h1:Qo5Xlf+slrosyMxBKbNoxpEmzB6y2C5FI4BHNdVOSyI=
github.com/goravel/framework v1.15.2 h1:wC76iwXWpYz3Oj+WQKw/kC4yGluDIeRdmPFKQW3t47M=
github.com/goravel/framework v1.15.2/go.mod h1:Qo5Xlf+slrosyMxBKbNoxpEmzB6y2C5FI4BHNdVOSyI=
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/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
Expand Down Expand Up @@ -529,8 +529,6 @@ github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6g
github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ=
github.com/samber/lo v1.47.0 h1:z7RynLwP5nbyRscyvcD043DWYoOcYRv3mV8lBeqOCLc=
github.com/samber/lo v1.47.0/go.mod h1:RmDH9Ct32Qy3gduHQuKJ3gW1fMHAnE/fAzQuf6He5cU=
github.com/savioxavier/termlink v1.4.1 h1:pFcd+XH8iQjL+2mB4buCDUo+CMt5kKsr8jGG+VLfYAg=
github.com/savioxavier/termlink v1.4.1/go.mod h1:5T5ePUlWbxCHIwyF8/Ez1qufOoGM89RCg9NvG+3G3gc=
github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ=
github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
Expand Down
15 changes: 11 additions & 4 deletions route.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/goravel/framework/support/color"
"github.com/goravel/framework/support/file"
"github.com/goravel/framework/support/json"
"github.com/savioxavier/termlink"
"github.com/goravel/framework/support/str"
)

var globalRecoverCallback func(ctx contractshttp.Context, err any) = func(ctx contractshttp.Context, err any) {
Expand Down Expand Up @@ -153,6 +153,9 @@ func (r *Route) Recover(callback func(ctx contractshttp.Context, err any)) {
// Listen listen server
// Listen 监听服务器
func (r *Route) Listen(l net.Listener) error {
r.outputRoutes()
color.Green().Println("[HTTP] Listening on: " + str.Of(l.Addr().String()).Start("http://").String())

return r.instance.Listener(l)
}

Expand All @@ -179,8 +182,12 @@ func (r *Route) ListenTLSWithCert(l net.Listener, certFile, keyFile string) erro
GetCertificate: tlsHandler.GetClientInfo,
}

r.outputRoutes()
color.Green().Println("[HTTPS] Listening on: " + str.Of(l.Addr().String()).Start("https://").String())

r.instance.SetTLSHandler(tlsHandler)
return r.Listen(tls.NewListener(l, tlsConfig))

return r.instance.Listener(tls.NewListener(l, tlsConfig))
}

// Run run server
Expand All @@ -197,7 +204,7 @@ func (r *Route) Run(host ...string) error {
}

r.outputRoutes()
color.Green().Println(termlink.Link("[HTTP] Listening and serving HTTP on", "http://"+host[0]))
color.Green().Println("[HTTP] Listening on: " + str.Of(host[0]).Start("http://").String())

return r.instance.Listen(host[0])
}
Expand Down Expand Up @@ -232,7 +239,7 @@ func (r *Route) RunTLSWithCert(host, certFile, keyFile string) error {
}

r.outputRoutes()
color.Green().Println(termlink.Link("[HTTPS] Listening and serving HTTPS on", "https://"+host))
color.Green().Println("[HTTPS] Listening on: " + str.Of(host).Start("https://").String())

return r.instance.ListenTLS(host, certFile, keyFile)
}
Expand Down
42 changes: 22 additions & 20 deletions route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ import (
"github.com/gofiber/template/html/v2"
contractshttp "github.com/goravel/framework/contracts/http"
"github.com/goravel/framework/contracts/validation"
configmocks "github.com/goravel/framework/mocks/config"
mocksconfig "github.com/goravel/framework/mocks/config"
"github.com/stretchr/testify/assert"
)

func TestRecoverWithCustomCallback(t *testing.T) {
mockConfig := configmocks.NewConfig(t)
mockConfig := mocksconfig.NewConfig(t)

mockConfig.On("GetBool", "http.drivers.fiber.prefork", false).Return(false).Once()
mockConfig.On("GetInt", "http.drivers.fiber.body_limit", 4096).Return(4096).Once()
Expand Down Expand Up @@ -53,7 +53,7 @@ func TestRecoverWithCustomCallback(t *testing.T) {
}

func TestFallback(t *testing.T) {
mockConfig := configmocks.NewConfig(t)
mockConfig := mocksconfig.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()
Expand All @@ -80,7 +80,7 @@ func TestFallback(t *testing.T) {
func TestListen(t *testing.T) {
var (
err error
mockConfig *configmocks.Config
mockConfig *mocksconfig.Config
route *Route
)

Expand Down Expand Up @@ -109,7 +109,8 @@ func TestListen(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
mockConfig = configmocks.NewConfig(t)
mockConfig = mocksconfig.NewConfig(t)
mockConfig.EXPECT().GetBool("app.debug").Return(true).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()
Expand Down Expand Up @@ -142,7 +143,7 @@ func TestListen(t *testing.T) {
func TestListenTLS(t *testing.T) {
var (
err error
mockConfig *configmocks.Config
mockConfig *mocksconfig.Config
route *Route
)

Expand All @@ -169,7 +170,8 @@ func TestListenTLS(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
mockConfig = configmocks.NewConfig(t)
mockConfig = mocksconfig.NewConfig(t)
mockConfig.EXPECT().GetBool("app.debug").Return(true).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()
Expand Down Expand Up @@ -205,7 +207,7 @@ func TestListenTLS(t *testing.T) {
func TestListenTLSWithCert(t *testing.T) {
var (
err error
mockConfig *configmocks.Config
mockConfig *mocksconfig.Config
route *Route
)

Expand All @@ -232,7 +234,8 @@ func TestListenTLSWithCert(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
mockConfig = configmocks.NewConfig(t)
mockConfig = mocksconfig.NewConfig(t)
mockConfig.EXPECT().GetBool("app.debug").Return(true).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()
Expand Down Expand Up @@ -266,7 +269,7 @@ func TestListenTLSWithCert(t *testing.T) {
func TestRun(t *testing.T) {
var (
err error
mockConfig *configmocks.Config
mockConfig *mocksconfig.Config
route *Route
)

Expand Down Expand Up @@ -327,7 +330,7 @@ func TestRun(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
mockConfig = configmocks.NewConfig(t)
mockConfig = mocksconfig.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()
Expand Down Expand Up @@ -362,7 +365,7 @@ func TestRun(t *testing.T) {
func TestRunTLS(t *testing.T) {
var (
err error
mockConfig *configmocks.Config
mockConfig *mocksconfig.Config
route *Route
)

Expand Down Expand Up @@ -425,7 +428,7 @@ func TestRunTLS(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
mockConfig = configmocks.NewConfig(t)
mockConfig = mocksconfig.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()
Expand Down Expand Up @@ -457,15 +460,14 @@ func TestRunTLS(t *testing.T) {
assert.Nil(t, err)
assert.Equal(t, "{\"Hello\":\"Goravel\"}", string(body))
}

})
}
}

func TestRunTLSWithCert(t *testing.T) {
var (
err error
mockConfig *configmocks.Config
mockConfig *mocksconfig.Config
route *Route
)

Expand Down Expand Up @@ -516,7 +518,7 @@ func TestRunTLSWithCert(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
mockConfig = configmocks.NewConfig(t)
mockConfig = mocksconfig.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()
Expand Down Expand Up @@ -550,7 +552,7 @@ func TestRunTLSWithCert(t *testing.T) {
}

func TestNewRoute(t *testing.T) {
var mockConfig *configmocks.Config
var mockConfig *mocksconfig.Config
template := html.New("./resources/views", ".tmpl")

tests := []struct {
Expand Down Expand Up @@ -607,7 +609,7 @@ func TestNewRoute(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
mockConfig = configmocks.NewConfig(t)
mockConfig = mocksconfig.NewConfig(t)
test.setup()
route, err := NewRoute(mockConfig, test.parameters)
assert.Equal(t, test.expectError, err)
Expand All @@ -622,7 +624,7 @@ func TestNewRoute(t *testing.T) {
func TestShutdown(t *testing.T) {
var (
err error
mockConfig *configmocks.Config
mockConfig *mocksconfig.Config
route *Route
count atomic.Int64
host = "127.0.0.1"
Expand Down Expand Up @@ -681,7 +683,7 @@ func TestShutdown(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
mockConfig = configmocks.NewConfig(t)
mockConfig = mocksconfig.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()
Expand Down

0 comments on commit 3115a42

Please sign in to comment.