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

✨ v3 (feature): merge Listen methods & ListenConfig #1930

Merged
merged 24 commits into from
Sep 8, 2022
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
6 changes: 5 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,8 @@ jobs:
- name: Fetch Repository
uses: actions/checkout@v3
- name: Run Test
run: go test ./... -v -race
uses: nick-fields/retry@v2
with:
max_attempts: 3
timeout_minutes: 15
command: go test ./... -v -race
26 changes: 2 additions & 24 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,6 @@ type App struct {

// Config is a struct holding the server settings.
type Config struct {
// When set to true, this will spawn multiple Go processes listening on the same port.
//
// Default: false
Prefork bool `json:"prefork"`

// Enables the "Server: value" HTTP header.
//
// Default: ""
Expand Down Expand Up @@ -270,11 +265,6 @@ type Config struct {
// Default: false
DisableHeaderNormalizing bool `json:"disable_header_normalizing"`

// When set to true, it will not print out the «Fiber» ASCII art and listening address.
//
// Default: false
DisableStartupMessage bool `json:"disable_startup_message"`

// This function allows to setup app name for the app
//
// Default: nil
Expand Down Expand Up @@ -332,12 +322,6 @@ type Config struct {
// Default: xml.Marshal
XMLEncoder utils.XMLMarshal `json:"-"`

// Known networks are "tcp", "tcp4" (IPv4-only), "tcp6" (IPv6-only)
// WARNING: When prefork is set to true, only "tcp4" and "tcp6" can be chose.
//
// Default: NetworkTCP4
Network string

// If you find yourself behind some sort of proxy, like a load balancer,
// then certain header information may be sent to you using special X-Forwarded-* headers or the Forwarded header.
// For example, the Host HTTP header is usually used to return the requested host.
Expand Down Expand Up @@ -374,10 +358,6 @@ type Config struct {
// Default: false
EnableIPValidation bool `json:"enable_ip_validation"`

// If set to true, will print all routes with their method, path and handler.
// Default: false
EnablePrintRoutes bool `json:"enable_print_routes"`

// You can define custom color scheme. They'll be used for startup message, route list and some middlewares.
//
// Optional. Default: DefaultColors
Expand Down Expand Up @@ -533,9 +513,6 @@ func New(config ...Config) *App {
if app.config.XMLEncoder == nil {
app.config.XMLEncoder = xml.Marshal
}
if app.config.Network == "" {
app.config.Network = NetworkTCP4
}

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

app.mutex.Lock()
Expand Down
31 changes: 11 additions & 20 deletions app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -597,16 +597,14 @@ func Test_App_New(t *testing.T) {

func Test_App_Config(t *testing.T) {
app := New(Config{
DisableStartupMessage: true,
StrictRouting: true,
})
require.True(t, app.Config().DisableStartupMessage)
require.True(t, app.Config().StrictRouting)
}

func Test_App_Shutdown(t *testing.T) {
t.Run("success", func(t *testing.T) {
app := New(Config{
DisableStartupMessage: true,
})
app := New()
require.True(t, app.Shutdown() == nil)
})

Expand Down Expand Up @@ -1096,7 +1094,6 @@ func Test_App_Deep_Group(t *testing.T) {
// go test -run Test_App_Next_Method
func Test_App_Next_Method(t *testing.T) {
app := New()
app.config.DisableStartupMessage = true

app.Use(func(c Ctx) error {
require.Equal(t, MethodGet, c.Method())
Expand Down Expand Up @@ -1138,7 +1135,6 @@ func Test_NewError(t *testing.T) {
// go test -run Test_Test_Timeout
func Test_Test_Timeout(t *testing.T) {
app := New()
app.config.DisableStartupMessage = true

app.Get("/", testEmptyHandler)

Expand All @@ -1164,7 +1160,6 @@ func (errorReader) Read([]byte) (int, error) {
// go test -run Test_Test_DumpError
func Test_Test_DumpError(t *testing.T) {
app := New()
app.config.DisableStartupMessage = true

app.Get("/", testEmptyHandler)

Expand Down Expand Up @@ -1234,10 +1229,9 @@ func Test_App_HandlersCount(t *testing.T) {
// go test -run Test_App_ReadTimeout
func Test_App_ReadTimeout(t *testing.T) {
app := New(Config{
ReadTimeout: time.Nanosecond,
IdleTimeout: time.Minute,
DisableStartupMessage: true,
DisableKeepalive: true,
ReadTimeout: time.Nanosecond,
IdleTimeout: time.Minute,
DisableKeepalive: true,
})

app.Get("/read-timeout", func(c Ctx) error {
Expand All @@ -1264,14 +1258,12 @@ func Test_App_ReadTimeout(t *testing.T) {
require.Nil(t, app.Shutdown())
}()

require.Nil(t, app.Listen(":4004"))
require.Nil(t, app.Listen(":4004", ListenConfig{DisableStartupMessage: true}))
}

// go test -run Test_App_BadRequest
func Test_App_BadRequest(t *testing.T) {
app := New(Config{
DisableStartupMessage: true,
})
app := New()

app.Get("/bad-request", func(c Ctx) error {
return c.SendString("I should not be sent")
Expand All @@ -1296,14 +1288,13 @@ func Test_App_BadRequest(t *testing.T) {
require.Nil(t, app.Shutdown())
}()

require.Nil(t, app.Listen(":4005"))
require.Nil(t, app.Listen(":4005", ListenConfig{DisableStartupMessage: true}))
}

// go test -run Test_App_SmallReadBuffer
func Test_App_SmallReadBuffer(t *testing.T) {
app := New(Config{
ReadBufferSize: 1,
DisableStartupMessage: true,
ReadBufferSize: 1,
})

app.Get("/small-read-buffer", func(c Ctx) error {
Expand All @@ -1320,7 +1311,7 @@ func Test_App_SmallReadBuffer(t *testing.T) {
require.Nil(t, app.Shutdown())
}()

require.Nil(t, app.Listen(":4006"))
require.Nil(t, app.Listen(":4006", ListenConfig{DisableStartupMessage: true}))
}

func Test_App_Server(t *testing.T) {
Expand Down
Loading