Skip to content

Commit 281e2f0

Browse files
efectnReneWerner87
andauthored
✨ v3 (feature): merge Listen methods & ListenConfig (#1930)
* ✨ v3: new Start method for app * ✨ v3: new Start method for app * ✨ v3: new Start method for app * ✨ v3: new Start method for app * ✨ v3: new Start method for app * ✨ v3: new Start method for app * fix tests * improve graceful shutdown * update * Start -> Listen * rename test funcs. * Add Test_Listen_Graceful_Shutdown test. * add OnShutdownSuccess * fix tests * fix tests * split listen & listener * typo * Add retry logic to tests * Add retry logic to tests * Add retry logic to tests * Add retry logic to tests Co-authored-by: René Werner <[email protected]>
1 parent ca0f663 commit 281e2f0

File tree

12 files changed

+714
-336
lines changed

12 files changed

+714
-336
lines changed

.github/workflows/test.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,8 @@ jobs:
3535
- name: Fetch Repository
3636
uses: actions/checkout@v3
3737
- name: Run Test
38-
run: go test ./... -v -race
38+
uses: nick-fields/retry@v2
39+
with:
40+
max_attempts: 3
41+
timeout_minutes: 15
42+
command: go test ./... -v -race

app.go

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,6 @@ type App struct {
124124

125125
// Config is a struct holding the server settings.
126126
type Config struct {
127-
// When set to true, this will spawn multiple Go processes listening on the same port.
128-
//
129-
// Default: false
130-
Prefork bool `json:"prefork"`
131-
132127
// Enables the "Server: value" HTTP header.
133128
//
134129
// Default: ""
@@ -270,11 +265,6 @@ type Config struct {
270265
// Default: false
271266
DisableHeaderNormalizing bool `json:"disable_header_normalizing"`
272267

273-
// When set to true, it will not print out the «Fiber» ASCII art and listening address.
274-
//
275-
// Default: false
276-
DisableStartupMessage bool `json:"disable_startup_message"`
277-
278268
// This function allows to setup app name for the app
279269
//
280270
// Default: nil
@@ -332,12 +322,6 @@ type Config struct {
332322
// Default: xml.Marshal
333323
XMLEncoder utils.XMLMarshal `json:"-"`
334324

335-
// Known networks are "tcp", "tcp4" (IPv4-only), "tcp6" (IPv6-only)
336-
// WARNING: When prefork is set to true, only "tcp4" and "tcp6" can be chose.
337-
//
338-
// Default: NetworkTCP4
339-
Network string
340-
341325
// If you find yourself behind some sort of proxy, like a load balancer,
342326
// then certain header information may be sent to you using special X-Forwarded-* headers or the Forwarded header.
343327
// For example, the Host HTTP header is usually used to return the requested host.
@@ -374,10 +358,6 @@ type Config struct {
374358
// Default: false
375359
EnableIPValidation bool `json:"enable_ip_validation"`
376360

377-
// If set to true, will print all routes with their method, path and handler.
378-
// Default: false
379-
EnablePrintRoutes bool `json:"enable_print_routes"`
380-
381361
// You can define custom color scheme. They'll be used for startup message, route list and some middlewares.
382362
//
383363
// Optional. Default: DefaultColors
@@ -533,9 +513,6 @@ func New(config ...Config) *App {
533513
if app.config.XMLEncoder == nil {
534514
app.config.XMLEncoder = xml.Marshal
535515
}
536-
if app.config.Network == "" {
537-
app.config.Network = NetworkTCP4
538-
}
539516

540517
app.config.trustedProxiesMap = make(map[string]struct{}, len(app.config.TrustedProxies))
541518
for _, ipAddress := range app.config.TrustedProxies {
@@ -831,7 +808,8 @@ func (app *App) HandlersCount() uint32 {
831808
// Shutdown does not close keepalive connections so its recommended to set ReadTimeout to something else than 0.
832809
func (app *App) Shutdown() error {
833810
if app.hooks != nil {
834-
defer app.hooks.executeOnShutdownHooks()
811+
// TODO: check should be defered?
812+
app.hooks.executeOnShutdownHooks()
835813
}
836814

837815
app.mutex.Lock()

app_test.go

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -599,16 +599,14 @@ func Test_App_New(t *testing.T) {
599599

600600
func Test_App_Config(t *testing.T) {
601601
app := New(Config{
602-
DisableStartupMessage: true,
602+
StrictRouting: true,
603603
})
604-
require.True(t, app.Config().DisableStartupMessage)
604+
require.True(t, app.Config().StrictRouting)
605605
}
606606

607607
func Test_App_Shutdown(t *testing.T) {
608608
t.Run("success", func(t *testing.T) {
609-
app := New(Config{
610-
DisableStartupMessage: true,
611-
})
609+
app := New()
612610
require.True(t, app.Shutdown() == nil)
613611
})
614612

@@ -1098,7 +1096,6 @@ func Test_App_Deep_Group(t *testing.T) {
10981096
// go test -run Test_App_Next_Method
10991097
func Test_App_Next_Method(t *testing.T) {
11001098
app := New()
1101-
app.config.DisableStartupMessage = true
11021099

11031100
app.Use(func(c Ctx) error {
11041101
require.Equal(t, MethodGet, c.Method())
@@ -1140,7 +1137,6 @@ func Test_NewError(t *testing.T) {
11401137
// go test -run Test_Test_Timeout
11411138
func Test_Test_Timeout(t *testing.T) {
11421139
app := New()
1143-
app.config.DisableStartupMessage = true
11441140

11451141
app.Get("/", testEmptyHandler)
11461142

@@ -1166,7 +1162,6 @@ func (errorReader) Read([]byte) (int, error) {
11661162
// go test -run Test_Test_DumpError
11671163
func Test_Test_DumpError(t *testing.T) {
11681164
app := New()
1169-
app.config.DisableStartupMessage = true
11701165

11711166
app.Get("/", testEmptyHandler)
11721167

@@ -1236,10 +1231,9 @@ func Test_App_HandlersCount(t *testing.T) {
12361231
// go test -run Test_App_ReadTimeout
12371232
func Test_App_ReadTimeout(t *testing.T) {
12381233
app := New(Config{
1239-
ReadTimeout: time.Nanosecond,
1240-
IdleTimeout: time.Minute,
1241-
DisableStartupMessage: true,
1242-
DisableKeepalive: true,
1234+
ReadTimeout: time.Nanosecond,
1235+
IdleTimeout: time.Minute,
1236+
DisableKeepalive: true,
12431237
})
12441238

12451239
app.Get("/read-timeout", func(c Ctx) error {
@@ -1266,14 +1260,12 @@ func Test_App_ReadTimeout(t *testing.T) {
12661260
require.Nil(t, app.Shutdown())
12671261
}()
12681262

1269-
require.Nil(t, app.Listen(":4004"))
1263+
require.Nil(t, app.Listen(":4004", ListenConfig{DisableStartupMessage: true}))
12701264
}
12711265

12721266
// go test -run Test_App_BadRequest
12731267
func Test_App_BadRequest(t *testing.T) {
1274-
app := New(Config{
1275-
DisableStartupMessage: true,
1276-
})
1268+
app := New()
12771269

12781270
app.Get("/bad-request", func(c Ctx) error {
12791271
return c.SendString("I should not be sent")
@@ -1298,14 +1290,13 @@ func Test_App_BadRequest(t *testing.T) {
12981290
require.Nil(t, app.Shutdown())
12991291
}()
13001292

1301-
require.Nil(t, app.Listen(":4005"))
1293+
require.Nil(t, app.Listen(":4005", ListenConfig{DisableStartupMessage: true}))
13021294
}
13031295

13041296
// go test -run Test_App_SmallReadBuffer
13051297
func Test_App_SmallReadBuffer(t *testing.T) {
13061298
app := New(Config{
1307-
ReadBufferSize: 1,
1308-
DisableStartupMessage: true,
1299+
ReadBufferSize: 1,
13091300
})
13101301

13111302
app.Get("/small-read-buffer", func(c Ctx) error {
@@ -1322,7 +1313,7 @@ func Test_App_SmallReadBuffer(t *testing.T) {
13221313
require.Nil(t, app.Shutdown())
13231314
}()
13241315

1325-
require.Nil(t, app.Listen(":4006"))
1316+
require.Nil(t, app.Listen(":4006", ListenConfig{DisableStartupMessage: true}))
13261317
}
13271318

13281319
func Test_App_Server(t *testing.T) {

0 commit comments

Comments
 (0)