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

🔗 Allow route method chaining #641

Merged
merged 60 commits into from
Jul 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
32838da
👷 improve test coverage
kiyonlin Jul 16, 2020
88f876d
🌼 separate different logic on each OS for child process to watch if m…
kiyonlin Jul 16, 2020
6d3c1df
🔔 fix ctx matched bug, it should be reset to false when acquired
kiyonlin Jul 17, 2020
b8c887b
👷 fixed #625
kiyonlin Jul 17, 2020
caf98ef
📀 Cores should be Threads
Fenny Jul 17, 2020
c46e037
🔌 Support TCP6 in Prefork mode
Fenny Jul 17, 2020
313885c
🧹 Handle TCP6 addr in Prefork
Fenny Jul 17, 2020
1dce1a0
🩹 Update IPv6 test
Fenny Jul 17, 2020
4554ea1
🔍 Auto detect TCP protocol
Fenny Jul 17, 2020
7f44f5b
🔍 detect tcp proto by addr
Fenny Jul 17, 2020
e4c3b66
🩹 ( ͡↑ ͜ʖ ͡↑) Test is failing
Fenny Jul 17, 2020
6b12150
🩹 ༼ ಥل͟ಥ ༽
Fenny Jul 17, 2020
61c21e8
🍡 o͡͡͡╮༼ ಠДಠ ༽╭o͡͡͡━☆゚.*・。゚ IPv6 support for Prefork
Fenny Jul 17, 2020
7c2f856
🧙‍♂️ Add IPv6 support for Prefork
Fenny Jul 17, 2020
b0cd847
🧙‍♂️ Add IPv6 Support in Prefork mode
Fenny Jul 17, 2020
a6223ad
📗 improve ctx.Render test
kiyonlin Jul 18, 2020
3a6c76c
💯 remain code coverage
kiyonlin Jul 18, 2020
b244760
:pencil2: Fix typo for app and ctx warnings
DarthBenro008 Jul 18, 2020
1b2d3d9
🔗Allow route method chaining
ReneWerner87 Jul 19, 2020
09c7776
👷 improve test coverage
kiyonlin Jul 16, 2020
2e1dde0
🌼 separate different logic on each OS for child process to watch if m…
kiyonlin Jul 16, 2020
95362e5
🔔 fix ctx matched bug, it should be reset to false when acquired
kiyonlin Jul 17, 2020
293207d
👷 fixed #625
kiyonlin Jul 17, 2020
f876d2f
📀 Cores should be Threads
Fenny Jul 17, 2020
225c6de
🔌 Support TCP6 in Prefork mode
Fenny Jul 17, 2020
0efbbca
🧹 Handle TCP6 addr in Prefork
Fenny Jul 17, 2020
6a3c328
🩹 Update IPv6 test
Fenny Jul 17, 2020
eaa78ab
🔍 Auto detect TCP protocol
Fenny Jul 17, 2020
fce3a3b
🔍 detect tcp proto by addr
Fenny Jul 17, 2020
d9e7df9
🩹 ( ͡↑ ͜ʖ ͡↑) Test is failing
Fenny Jul 17, 2020
8aac136
🩹 ༼ ಥل͟ಥ ༽
Fenny Jul 17, 2020
a2c9808
🍡 o͡͡͡╮༼ ಠДಠ ༽╭o͡͡͡━☆゚.*・。゚ IPv6 support for Prefork
Fenny Jul 17, 2020
76b8b6e
🧙‍♂️ Add IPv6 support for Prefork
Fenny Jul 17, 2020
2acb4a0
🧙‍♂️ Add IPv6 Support in Prefork mode
Fenny Jul 17, 2020
fcde4bb
📗 improve ctx.Render test
kiyonlin Jul 18, 2020
66bdd5b
💯 remain code coverage
kiyonlin Jul 18, 2020
d973864
:pencil2: Fix typo for app and ctx warnings
DarthBenro008 Jul 18, 2020
3e808bb
Merge branch 'master' of https://github.com/gofiber/fiber
ReneWerner87 Jul 19, 2020
97c8b10
👷 improve test coverage
kiyonlin Jul 16, 2020
4f2d1f6
🌼 separate different logic on each OS for child process to watch if m…
kiyonlin Jul 16, 2020
e2a614b
🔔 fix ctx matched bug, it should be reset to false when acquired
kiyonlin Jul 17, 2020
1cb91ad
👷 fixed #625
kiyonlin Jul 17, 2020
662b21b
📀 Cores should be Threads
Fenny Jul 17, 2020
1ae1e8c
🔌 Support TCP6 in Prefork mode
Fenny Jul 17, 2020
ac01a17
🧹 Handle TCP6 addr in Prefork
Fenny Jul 17, 2020
50c0da5
🩹 Update IPv6 test
Fenny Jul 17, 2020
e15f77e
🔍 Auto detect TCP protocol
Fenny Jul 17, 2020
4b2bbd9
🔍 detect tcp proto by addr
Fenny Jul 17, 2020
fb9516e
🩹 ( ͡↑ ͜ʖ ͡↑) Test is failing
Fenny Jul 17, 2020
1f35688
🩹 ༼ ಥل͟ಥ ༽
Fenny Jul 17, 2020
b608948
🍡 o͡͡͡╮༼ ಠДಠ ༽╭o͡͡͡━☆゚.*・。゚ IPv6 support for Prefork
Fenny Jul 17, 2020
460ab2a
🧙‍♂️ Add IPv6 support for Prefork
Fenny Jul 17, 2020
8a61775
🧙‍♂️ Add IPv6 Support in Prefork mode
Fenny Jul 17, 2020
c3b5de6
📗 improve ctx.Render test
kiyonlin Jul 18, 2020
79981c5
💯 remain code coverage
kiyonlin Jul 18, 2020
53c7cdf
:pencil2: Fix typo for app and ctx warnings
DarthBenro008 Jul 18, 2020
3af6712
Merge branch 'master' of https://github.com/gofiber/fiber
ReneWerner87 Jul 19, 2020
0292357
Merge remote-tracking branch 'origin/master'
ReneWerner87 Jul 19, 2020
fb3f8ae
Merge remote-tracking branch 'origin/master' into route_chaining
ReneWerner87 Jul 19, 2020
dd0a283
Merge remote-tracking branch 'origin/master' into route_chaining
ReneWerner87 Jul 19, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
44 changes: 23 additions & 21 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ func New(settings ...*Settings) *App {
// app.Use(handler)
// app.Use("/api", handler)
// app.Use("/api", handler, handler)
func (app *App) Use(args ...interface{}) *Route {
func (app *App) Use(args ...interface{}) Router {
var prefix string
var handlers []Handler

Expand All @@ -300,83 +300,85 @@ func (app *App) Use(args ...interface{}) *Route {
panic(fmt.Sprintf("use: invalid handler %v\n", reflect.TypeOf(arg)))
}
}
return app.register(methodUse, prefix, handlers...)
_ = app.register(methodUse, prefix, handlers...)
return app
}

// Get registers a route for GET methods that requests a representation
// of the specified resource. Requests using GET should only retrieve data.
func (app *App) Get(path string, handlers ...Handler) *Route {
func (app *App) Get(path string, handlers ...Handler) Router {
return app.Add(MethodGet, path, handlers...)
}

// Head registers a route for HEAD methods that asks for a response identical
// to that of a GET request, but without the response body.
func (app *App) Head(path string, handlers ...Handler) *Route {
func (app *App) Head(path string, handlers ...Handler) Router {
return app.Add(MethodHead, path, handlers...)
}

// Post registers a route for POST methods that is used to submit an entity to the
// specified resource, often causing a change in state or side effects on the server.
func (app *App) Post(path string, handlers ...Handler) *Route {
func (app *App) Post(path string, handlers ...Handler) Router {
return app.Add(MethodPost, path, handlers...)
}

// Put registers a route for PUT methods that replaces all current representations
// of the target resource with the request payload.
func (app *App) Put(path string, handlers ...Handler) *Route {
func (app *App) Put(path string, handlers ...Handler) Router {
return app.Add(MethodPut, path, handlers...)
}

// Delete registers a route for DELETE methods that deletes the specified resource.
func (app *App) Delete(path string, handlers ...Handler) *Route {
func (app *App) Delete(path string, handlers ...Handler) Router {
return app.Add(MethodDelete, path, handlers...)
}

// Connect registers a route for CONNECT methods that establishes a tunnel to the
// server identified by the target resource.
func (app *App) Connect(path string, handlers ...Handler) *Route {
func (app *App) Connect(path string, handlers ...Handler) Router {
return app.Add(MethodConnect, path, handlers...)
}

// Options registers a route for OPTIONS methods that is used to describe the
// communication options for the target resource.
func (app *App) Options(path string, handlers ...Handler) *Route {
func (app *App) Options(path string, handlers ...Handler) Router {
return app.Add(MethodOptions, path, handlers...)
}

// Trace registers a route for TRACE methods that performs a message loop-back
// test along the path to the target resource.
func (app *App) Trace(path string, handlers ...Handler) *Route {
func (app *App) Trace(path string, handlers ...Handler) Router {
return app.Add(MethodTrace, path, handlers...)
}

// Patch registers a route for PATCH methods that is used to apply partial
// modifications to a resource.
func (app *App) Patch(path string, handlers ...Handler) *Route {
func (app *App) Patch(path string, handlers ...Handler) Router {
return app.Add(MethodPatch, path, handlers...)
}

// Add ...
func (app *App) Add(method, path string, handlers ...Handler) *Route {
return app.register(method, path, handlers...)
func (app *App) Add(method, path string, handlers ...Handler) Router {
_ = app.register(method, path, handlers...)
return app
}

// Static ...
func (app *App) Static(prefix, root string, config ...Static) *Route {
return app.registerStatic(prefix, root, config...)
func (app *App) Static(prefix, root string, config ...Static) Router {
_ = app.registerStatic(prefix, root, config...)
return app
}

// All ...
func (app *App) All(path string, handlers ...Handler) []*Route {
routes := make([]*Route, len(intMethod))
for i, method := range intMethod {
routes[i] = app.Add(method, path, handlers...)
func (app *App) All(path string, handlers ...Handler) Router {
for _, method := range intMethod {
_ = app.Add(method, path, handlers...)
}
return routes
return app
}

// Group is used for Routes with common prefix to define a new sub-router with optional middleware.
func (app *App) Group(prefix string, handlers ...Handler) *Group {
func (app *App) Group(prefix string, handlers ...Handler) Router {
if len(handlers) > 0 {
app.register(methodUse, prefix, handlers...)
}
Expand Down
46 changes: 24 additions & 22 deletions group.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type Group struct {
// - group.Use(handler)
// - group.Use("/api", handler)
// - group.Use("/api", handler, handler)
func (grp *Group) Use(args ...interface{}) *Route {
func (grp *Group) Use(args ...interface{}) Router {
var path = ""
var handlers []Handler
for i := 0; i < len(args); i++ {
Expand All @@ -35,86 +35,88 @@ func (grp *Group) Use(args ...interface{}) *Route {
panic(fmt.Sprintf("use: invalid handler %v\n", reflect.TypeOf(arg)))
}
}
return grp.app.register(methodUse, getGroupPath(grp.prefix, path), handlers...)
_ = grp.app.register(methodUse, getGroupPath(grp.prefix, path), handlers...)
return grp
}

// Get registers a route for GET methods that requests a representation
// of the specified resource. Requests using GET should only retrieve data.
func (grp *Group) Get(path string, handlers ...Handler) *Route {
func (grp *Group) Get(path string, handlers ...Handler) Router {
return grp.Add(MethodGet, path, handlers...)
}

// Head registers a route for HEAD methods that asks for a response identical
// to that of a GET request, but without the response body.
func (grp *Group) Head(path string, handlers ...Handler) *Route {
func (grp *Group) Head(path string, handlers ...Handler) Router {
return grp.Add(MethodHead, path, handlers...)
}

// Post registers a route for POST methods that is used to submit an entity to the
// specified resource, often causing a change in state or side effects on the server.
func (grp *Group) Post(path string, handlers ...Handler) *Route {
func (grp *Group) Post(path string, handlers ...Handler) Router {
return grp.Add(MethodPost, path, handlers...)
}

// Put registers a route for PUT methods that replaces all current representations
// of the target resource with the request payload.
func (grp *Group) Put(path string, handlers ...Handler) *Route {
func (grp *Group) Put(path string, handlers ...Handler) Router {
return grp.Add(MethodPut, path, handlers...)
}

// Delete registers a route for DELETE methods that deletes the specified resource.
func (grp *Group) Delete(path string, handlers ...Handler) *Route {
func (grp *Group) Delete(path string, handlers ...Handler) Router {
return grp.Add(MethodDelete, path, handlers...)
}

// Connect registers a route for CONNECT methods that establishes a tunnel to the
// server identified by the target resource.
func (grp *Group) Connect(path string, handlers ...Handler) *Route {
func (grp *Group) Connect(path string, handlers ...Handler) Router {
return grp.Add(MethodConnect, path, handlers...)
}

// Options registers a route for OPTIONS methods that is used to describe the
// communication options for the target resource.
func (grp *Group) Options(path string, handlers ...Handler) *Route {
func (grp *Group) Options(path string, handlers ...Handler) Router {
return grp.Add(MethodOptions, path, handlers...)
}

// Trace registers a route for TRACE methods that performs a message loop-back
// test along the path to the target resource.
func (grp *Group) Trace(path string, handlers ...Handler) *Route {
func (grp *Group) Trace(path string, handlers ...Handler) Router {
return grp.Add(MethodTrace, path, handlers...)
}

// Patch registers a route for PATCH methods that is used to apply partial
// modifications to a resource.
func (grp *Group) Patch(path string, handlers ...Handler) *Route {
func (grp *Group) Patch(path string, handlers ...Handler) Router {
return grp.Add(MethodPatch, path, handlers...)
}

// Add ...
func (grp *Group) Add(method, path string, handlers ...Handler) *Route {
return grp.app.register(method, getGroupPath(grp.prefix, path), handlers...)
func (grp *Group) Add(method, path string, handlers ...Handler) Router {
_ = grp.app.register(method, getGroupPath(grp.prefix, path), handlers...)
return grp
}

// Static ...
func (grp *Group) Static(prefix, root string, config ...Static) *Route {
return grp.app.registerStatic(getGroupPath(grp.prefix, prefix), root, config...)
func (grp *Group) Static(prefix, root string, config ...Static) Router {
_ = grp.app.registerStatic(getGroupPath(grp.prefix, prefix), root, config...)
return grp
}

// All ...
func (grp *Group) All(path string, handlers ...Handler) []*Route {
routes := make([]*Route, len(intMethod))
for i, method := range intMethod {
routes[i] = grp.Add(method, path, handlers...)
func (grp *Group) All(path string, handlers ...Handler) Router {
for _, method := range intMethod {
_ = grp.Add(method, path, handlers...)
}
return routes
return grp
}

// Group is used for Routes with common prefix to define a new sub-router with optional middleware.
func (grp *Group) Group(prefix string, handlers ...Handler) *Group {
func (grp *Group) Group(prefix string, handlers ...Handler) Router {
prefix = getGroupPath(grp.prefix, prefix)
if len(handlers) > 0 {
grp.app.register(methodUse, prefix, handlers...)
_ = grp.app.register(methodUse, prefix, handlers...)
}
return grp.app.Group(prefix)
}
28 changes: 14 additions & 14 deletions router.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@ import (

// Router defines all router handle interface includes app and group router.
type Router interface {
Use(args ...interface{}) *Route
Use(args ...interface{}) Router

Get(path string, handlers ...Handler) *Route
Head(path string, handlers ...Handler) *Route
Post(path string, handlers ...Handler) *Route
Put(path string, handlers ...Handler) *Route
Delete(path string, handlers ...Handler) *Route
Connect(path string, handlers ...Handler) *Route
Options(path string, handlers ...Handler) *Route
Trace(path string, handlers ...Handler) *Route
Patch(path string, handlers ...Handler) *Route
Get(path string, handlers ...Handler) Router
Head(path string, handlers ...Handler) Router
Post(path string, handlers ...Handler) Router
Put(path string, handlers ...Handler) Router
Delete(path string, handlers ...Handler) Router
Connect(path string, handlers ...Handler) Router
Options(path string, handlers ...Handler) Router
Trace(path string, handlers ...Handler) Router
Patch(path string, handlers ...Handler) Router

Add(method, path string, handlers ...Handler) *Route
Static(prefix, root string, config ...Static) *Route
All(path string, handlers ...Handler) []*Route
Add(method, path string, handlers ...Handler) Router
Static(prefix, root string, config ...Static) Router
All(path string, handlers ...Handler) Router

Group(prefix string, handlers ...Handler) *Group
Group(prefix string, handlers ...Handler) Router
}

// Route is a struct that holds all metadata for each registered handler
Expand Down