Skip to content

Commit

Permalink
feat: add Shutdown to support graceful quit of HTTP Server (#98)
Browse files Browse the repository at this point in the history
* add Shutdown to support graceful quit of HTTP Server

* improve unit testing

---------

Co-authored-by: 朱祥东 <[email protected]>
  • Loading branch information
zxdstyle and 朱祥东 authored Sep 6, 2024
1 parent f560eaf commit 69eeba1
Show file tree
Hide file tree
Showing 4 changed files with 161 additions and 57 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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.3
github.com/goravel/framework v1.14.5-0.20240904064435-05476fa00c9c
github.com/savioxavier/termlink v1.3.0
github.com/spf13/cast v1.6.0
github.com/stretchr/testify v1.9.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,8 @@ 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.3 h1:H2sKrmsxCvVGRBbeewjXXLWsCAvk1o5kVskNymDfpfw=
github.com/goravel/framework v1.14.3/go.mod h1:rScDXGQZdoVfyxemNPmijlz/2a+lWNOa4jTuak5GGVg=
github.com/goravel/framework v1.14.5-0.20240904064435-05476fa00c9c h1:RiMpkbasXxmNmE/pLCy6lqmu3uOadyhICiqMtgroA7I=
github.com/goravel/framework v1.14.5-0.20240904064435-05476fa00c9c/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=
Expand Down
7 changes: 7 additions & 0 deletions route.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package fiber

import (
"context"
"errors"
"fmt"
"net/http"
Expand Down Expand Up @@ -184,6 +185,12 @@ 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 {
return r.instance.ShutdownWithContext(ctx)
}

// ServeHTTP serve http request (Not support)
// ServeHTTP 服务 HTTP 请求 (不支持)
func (r *Route) ServeHTTP(writer http.ResponseWriter, request *http.Request) {
Expand Down
Loading

0 comments on commit 69eeba1

Please sign in to comment.