diff --git a/Gopkg.lock b/Gopkg.lock
index 6bf5e157..4ce68abb 100644
--- a/Gopkg.lock
+++ b/Gopkg.lock
@@ -158,7 +158,7 @@
version = "v1.0.0"
[[projects]]
- name = "github.com/russross/blackfriday"
+ name = "gopkg.in/russross/blackfriday.v2"
packages = ["."]
revision = "cadec560ec52d93835bf2f15bd794700d3a2473b"
version = "v2.0.0"
diff --git a/Gopkg.toml b/Gopkg.toml
index e5d08baf..bae0c6d9 100644
--- a/Gopkg.toml
+++ b/Gopkg.toml
@@ -55,8 +55,8 @@
name = "github.com/microcosm-cc/bluemonday"
[[constraint]]
- name = "github.com/russross/blackfriday"
- version = "2.0.0"
+ branch = "v2"
+ name = "gopkg.in/russross/blackfriday.v2"
[[constraint]]
branch = "master"
diff --git a/HISTORY.md b/HISTORY.md
index 18dc21fa..f9c5331c 100644
--- a/HISTORY.md
+++ b/HISTORY.md
@@ -17,6 +17,27 @@ Developers are not forced to upgrade if they don't really need it. Upgrade whene
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris` or let the automatic updater do that for you.
+# Th, 08 February 2018 | v10.2.0
+
+A new minor version family because it contains a **BREAKING CHANGE** and a new `Party#Reset` function.
+
+### Party#Done behavior change & new Party#DoneGlobal introduced
+
+As correctly pointed out by @likakuli at https://github.com/kataras/iris/issues/901, the old `Done` registered
+handlers globally instead of party's and its children routes, this was not by accident because `Done` was introduced
+before the `UseGlobal` idea and it didn't change for the shake of stability. Now it's time to move on, the new `Done` should be called before the routes that they care about those done handlers and the **new** `DoneGlobal` works like the old `Done`; order doesn't matter and it appends those done handlers
+to the current registered routes and the future, globally (to all subdomains, parties every route in the Application).
+
+The [routing/writing-a-middleware](_examples/routing/writing-a-middleware) examples are updated, read those to understand what's going on, although if you used iris before and you know the vocabulary we use you don't have to, the `DoneGlobal` and `Done` are clearly separated.
+
+### Party#Reset
+
+A new `Party#Reset()` function introduced in order to be able to clear parent's Party's begin and done handlers that are registered via `Use` and `Done` at a previous state, nothing crazy about this, it just clears the `middleware` and `doneHandlers` of the current Party instance, see `core/router#APIBuilder` for more.
+
+### Update your codebase
+
+Just replace all existing `.Done(` with `.DoneGlobal(` using a rich code editor (like the [VSCode](https://marketplace.visualstudio.com/items?itemName=kataras2006.iris)) which supports `find and replace all` and you're ready to Go:)
+
# Tu, 06 February 2018 | v10.1.0
New Features:
diff --git a/HISTORY_GR.md b/HISTORY_GR.md
index 85cf7565..52a6f5bd 100644
--- a/HISTORY_GR.md
+++ b/HISTORY_GR.md
@@ -17,9 +17,13 @@
**Πώς να αναβαθμίσετε**: Ανοίξτε την γραμμή εντολών σας και εκτελέστε αυτήν την εντολή: `go get -u github.com/kataras/iris` ή αφήστε το αυτόματο updater να το κάνει αυτό για σας.
+# Th, 08 February 2018 | v10.2.0
+
+This history entry is not yet translated to Greek. Please read [the english version instead](https://github.com/kataras/iris/blob/master/HISTORY.md#th-08-february-2018--v1020).
+
# Tu, 06 February 2018 | v10.1.0
-This history entry is not yet translated to Chinese. Please read [the english version instead](https://github.com/kataras/iris/blob/master/HISTORY.md#tu-06-february-2018--v1010).
+This history entry is not yet translated to Greek. Please read [the english version instead](https://github.com/kataras/iris/blob/master/HISTORY.md#tu-06-february-2018--v1010).
# Tu, 16 January 2018 | v10.0.2
diff --git a/HISTORY_ZH.md b/HISTORY_ZH.md
index 2a811ec3..91f979fc 100644
--- a/HISTORY_ZH.md
+++ b/HISTORY_ZH.md
@@ -17,6 +17,10 @@
**如何升级**: 打开命令行执行以下命令: `go get -u github.com/kataras/iris` 或者等待自动更新。
+# Th, 08 February 2018 | v10.2.0
+
+This history entry is not yet translated to Chinese. Please read [the english version instead](https://github.com/kataras/iris/blob/master/HISTORY.md#th-08-february-2018--v1020).
+
# 2018 2月6号 | v10.1.0 版本更新
新特性:
diff --git a/README.md b/README.md
index 98c7f37a..18d96ac9 100644
--- a/README.md
+++ b/README.md
@@ -2,7 +2,7 @@
-[![build status](https://img.shields.io/travis/kataras/iris/master.svg?style=flat-square)](https://travis-ci.org/kataras/iris) [![report card](https://img.shields.io/badge/report%20card-a%2B-ff3333.svg?style=flat-square)](http://goreportcard.com/report/kataras/iris) [![vscode-iris](https://img.shields.io/badge/ext%20-vscode-0c77e3.svg?style=flat-square)](https://marketplace.visualstudio.com/items?itemName=kataras2006.iris) [![chat](https://img.shields.io/badge/community-%20chat-00BCD4.svg?style=flat-square)](https://kataras.rocket.chat/channel/iris) [![view examples](https://img.shields.io/badge/learn%20by-examples-0077b3.svg?style=flat-square)](_examples/) [![release](https://img.shields.io/badge/release%20-v10.1-0077b3.svg?style=flat-square)](https://github.com/kataras/iris/releases)
+[![build status](https://img.shields.io/travis/kataras/iris/master.svg?style=flat-square)](https://travis-ci.org/kataras/iris) [![report card](https://img.shields.io/badge/report%20card-a%2B-ff3333.svg?style=flat-square)](http://goreportcard.com/report/kataras/iris) [![vscode-iris](https://img.shields.io/badge/ext%20-vscode-0c77e3.svg?style=flat-square)](https://marketplace.visualstudio.com/items?itemName=kataras2006.iris) [![chat](https://img.shields.io/badge/community-%20chat-00BCD4.svg?style=flat-square)](https://kataras.rocket.chat/channel/iris) [![view examples](https://img.shields.io/badge/learn%20by-examples-0077b3.svg?style=flat-square)](_examples/) [![release](https://img.shields.io/badge/release%20-v10.2-0077b3.svg?style=flat-square)](https://github.com/kataras/iris/releases)
Iris is a fast, simple yet fully featured and very efficient web framework for Go.
@@ -106,10 +106,10 @@ _Updated at: [Tuesday, 21 November 2017](_benchmarks/README_UNIX.md)_
## Support
-- [HISTORY](HISTORY.md#tu-06-february-2018--v1010) file is your best friend, it contains information about the latest features and changes
+- [HISTORY](HISTORY.md#th-08-february-2018--v1020) file is your best friend, it contains information about the latest features and changes
- Did you happen to find a bug? Post it at [github issues](https://github.com/kataras/iris/issues)
- Do you have any questions or need to speak with someone experienced to solve a problem at real-time? Join us to the [community chat](https://chat.iris-go.com)
-- Complete our form-based user experience report by clicking [here](https://docs.google.com/forms/d/e/1FAIpQLSdCxZXPANg_xHWil4kVAdhmh7EBBHQZ_4_xSZVDL-oCC_z5pA/viewform?usp=sf_link)
+- Complete our form-based user experience report by clicking [here](https://docs.google.com/forms/d/e/1FAIpQLSdCxZXPANg_xHWil4kVAdhmh7EBBHQZ_4_xSZVDL-oCC_z5pA/viewform?usp=sf_link)
- Do you like the framework? Tweet something about it! The People have spoken:
diff --git a/README_GR.md b/README_GR.md
index 6c9354b1..365ef6af 100644
--- a/README_GR.md
+++ b/README_GR.md
@@ -2,7 +2,7 @@
-[![build status](https://img.shields.io/travis/kataras/iris/master.svg?style=flat-square)](https://travis-ci.org/kataras/iris) [![report card](https://img.shields.io/badge/report%20card-a%2B-ff3333.svg?style=flat-square)](http://goreportcard.com/report/kataras/iris) [![vscode-iris](https://img.shields.io/badge/ext%20-vscode-0c77e3.svg?style=flat-square)](https://marketplace.visualstudio.com/items?itemName=kataras2006.iris) [![chat](https://img.shields.io/badge/community-%20chat-00BCD4.svg?style=flat-square)](https://kataras.rocket.chat/channel/iris) [![view examples](https://img.shields.io/badge/learn%20by-examples-0077b3.svg?style=flat-square)](_examples/) [![release](https://img.shields.io/badge/release%20-v10.0-0077b3.svg?style=flat-square)](https://github.com/kataras/iris/releases)
+[![build status](https://img.shields.io/travis/kataras/iris/master.svg?style=flat-square)](https://travis-ci.org/kataras/iris) [![report card](https://img.shields.io/badge/report%20card-a%2B-ff3333.svg?style=flat-square)](http://goreportcard.com/report/kataras/iris) [![vscode-iris](https://img.shields.io/badge/ext%20-vscode-0c77e3.svg?style=flat-square)](https://marketplace.visualstudio.com/items?itemName=kataras2006.iris) [![chat](https://img.shields.io/badge/community-%20chat-00BCD4.svg?style=flat-square)](https://kataras.rocket.chat/channel/iris) [![view examples](https://img.shields.io/badge/learn%20by-examples-0077b3.svg?style=flat-square)](_examples/) [![release](https://img.shields.io/badge/release%20-v10.2-0077b3.svg?style=flat-square)](https://github.com/kataras/iris/releases)
Το Iris είναι ένα γρήγορο, απλό αλλά και πλήρως λειτουργικό και πολύ αποδοτικό web framework για τη Go.
@@ -108,7 +108,7 @@ _Η τελευταία ενημέρωση έγινε την [Τρίτη, 21 Νο
## Υποστήριξη
-- To [HISTORY](HISTORY_GR.md#tu-06-february-2018--v1010) αρχείο είναι ο καλύτερος σας φίλος, περιέχει πληροφορίες σχετικά με τις τελευταίες λειτουργίες(features) και αλλαγές
+- To [HISTORY](HISTORY_GR.md#th-08-february-2018--v1020) αρχείο είναι ο καλύτερος σας φίλος, περιέχει πληροφορίες σχετικά με τις τελευταίες λειτουργίες(features) και αλλαγές
- Μήπως τυχαίνει να βρήκατε κάποιο bug; Δημοσιεύστε το στα [github issues](https://github.com/kataras/iris/issues)
- Έχετε οποιεσδήποτε ερωτήσεις ή πρέπει να μιλήσετε με κάποιον έμπειρο για την επίλυση ενός προβλήματος σε πραγματικό χρόνο; Ελάτε μαζί μας στην [συνομιλία κοινότητας](https://chat.iris-go.com)
- Συμπληρώστε την αναφορά εμπειρίας χρήστη κάνοντας κλικ [εδώ](https://docs.google.com/forms/d/e/1FAIpQLSdCxZXPANg_xHWil4kVAdhmh7EBBHQZ_4_xSZVDL-oCC_z5pA/viewform?usp=sf_link)
diff --git a/README_RU.md b/README_RU.md
index a4cf2da7..3476ecab 100644
--- a/README_RU.md
+++ b/README_RU.md
@@ -2,7 +2,7 @@
-[![build status](https://img.shields.io/travis/kataras/iris/master.svg?style=flat-square)](https://travis-ci.org/kataras/iris) [![report card](https://img.shields.io/badge/report%20card-a%2B-ff3333.svg?style=flat-square)](http://goreportcard.com/report/kataras/iris) [![vscode-iris](https://img.shields.io/badge/ext%20-vscode-0c77e3.svg?style=flat-square)](https://marketplace.visualstudio.com/items?itemName=kataras2006.iris) [![chat](https://img.shields.io/badge/community-%20chat-00BCD4.svg?style=flat-square)](https://kataras.rocket.chat/channel/iris) [![view examples](https://img.shields.io/badge/learn%20by-examples-0077b3.svg?style=flat-square)](_examples/) [![release](https://img.shields.io/badge/release%20-v10.0-0077b3.svg?style=flat-square)](https://github.com/kataras/iris/releases)
+[![build status](https://img.shields.io/travis/kataras/iris/master.svg?style=flat-square)](https://travis-ci.org/kataras/iris) [![report card](https://img.shields.io/badge/report%20card-a%2B-ff3333.svg?style=flat-square)](http://goreportcard.com/report/kataras/iris) [![vscode-iris](https://img.shields.io/badge/ext%20-vscode-0c77e3.svg?style=flat-square)](https://marketplace.visualstudio.com/items?itemName=kataras2006.iris) [![chat](https://img.shields.io/badge/community-%20chat-00BCD4.svg?style=flat-square)](https://kataras.rocket.chat/channel/iris) [![view examples](https://img.shields.io/badge/learn%20by-examples-0077b3.svg?style=flat-square)](_examples/) [![release](https://img.shields.io/badge/release%20-v10.2-0077b3.svg?style=flat-square)](https://github.com/kataras/iris/releases)
Iris - это быстрая, простая, но полнофункциональная и очень эффективная веб-платформа для Go.
@@ -106,7 +106,7 @@ _Обновлено: [Вторник, 21 ноября 2017 г.](_benchmarks/READ
## Поддержка
-- Файл [HISTORY](HISTORY.md#tu-06-february-2018--v1010) - ваш лучший друг, он содержит информацию о последних особенностях и всех изменениях
+- Файл [HISTORY](HISTORY.md#th-08-february-2018--v1020) - ваш лучший друг, он содержит информацию о последних особенностях и всех изменениях
- Вы случайно обнаружили ошибку? Опубликуйте ее на [Github вопросы](https://github.com/kataras/iris/issues)
- У Вас есть какие-либо вопросы или Вам нужно поговорить с кем-то, кто бы смог решить Вашу проблему в режиме реального времени? Присоединяйтесь к нам в [чате сообщества](https://chat.iris-go.com)
- Заполните наш отчет о пользовательском опыте на основе формы, нажав [здесь](https://docs.google.com/forms/d/e/1FAIpQLSdCxZXPANg_xHWil4kVAdhmh7EBBHQZ_4_xSZVDL-oCC_z5pA/viewform?usp=sf_link)
diff --git a/README_ZH.md b/README_ZH.md
index 950429ce..1f3930d9 100644
--- a/README_ZH.md
+++ b/README_ZH.md
@@ -2,7 +2,7 @@
-[![build status](https://img.shields.io/travis/kataras/iris/master.svg?style=flat-square)](https://travis-ci.org/kataras/iris) [![report card](https://img.shields.io/badge/report%20card-a%2B-ff3333.svg?style=flat-square)](http://goreportcard.com/report/kataras/iris) [![vscode-iris](https://img.shields.io/badge/ext%20-vscode-0c77e3.svg?style=flat-square)](https://marketplace.visualstudio.com/items?itemName=kataras2006.iris) [![chat](https://img.shields.io/badge/community-%20chat-00BCD4.svg?style=flat-square)](https://kataras.rocket.chat/channel/iris) [![view examples](https://img.shields.io/badge/learn%20by-examples-0077b3.svg?style=flat-square)](_examples/) [![release](https://img.shields.io/badge/release%20-v10.0-0077b3.svg?style=flat-square)](https://github.com/kataras/iris/releases)
+[![build status](https://img.shields.io/travis/kataras/iris/master.svg?style=flat-square)](https://travis-ci.org/kataras/iris) [![report card](https://img.shields.io/badge/report%20card-a%2B-ff3333.svg?style=flat-square)](http://goreportcard.com/report/kataras/iris) [![vscode-iris](https://img.shields.io/badge/ext%20-vscode-0c77e3.svg?style=flat-square)](https://marketplace.visualstudio.com/items?itemName=kataras2006.iris) [![chat](https://img.shields.io/badge/community-%20chat-00BCD4.svg?style=flat-square)](https://kataras.rocket.chat/channel/iris) [![view examples](https://img.shields.io/badge/learn%20by-examples-0077b3.svg?style=flat-square)](_examples/) [![release](https://img.shields.io/badge/release%20-v10.2-0077b3.svg?style=flat-square)](https://github.com/kataras/iris/releases)
Iris 是一款超快、简洁高效的 Go 语言 Web开发框架。
@@ -102,7 +102,7 @@ _更新于: [2017年11月21日星期二](_benchmarks/README_UNIX.md)_
## 支持
-- [更新记录](HISTORY_ZH.md#tu-06-february-2018--v1010) 是您最好的朋友,它包含有关最新功能和更改的信息
+- [更新记录](HISTORY_ZH.md#th-08-february-2018--v1020) 是您最好的朋友,它包含有关最新功能和更改的信息
- 你碰巧找到了一个错误? 请提交 [github issues](https://github.com/kataras/iris/issues)
- 您是否有任何疑问或需要与有经验的人士交谈以实时解决问题? [加入我们的聊天](https://chat.iris-go.com)
- [点击这里完成我们基于表单的用户体验报告](https://docs.google.com/forms/d/e/1FAIpQLSdCxZXPANg_xHWil4kVAdhmh7EBBHQZ_4_xSZVDL-oCC_z5pA/viewform?usp=sf_link)
diff --git a/VERSION b/VERSION
index 943c0990..b59967f3 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-10.1.0:https://github.com/kataras/iris/blob/master/HISTORY.md#tu-06-february-2018--v1010
\ No newline at end of file
+10.2.0:https://github.com/kataras/iris/blob/master/HISTORY.md#th-08-february-2018--v1020
\ No newline at end of file
diff --git a/_examples/routing/README.md b/_examples/routing/README.md
index 5b85c202..6bf32e2a 100644
--- a/_examples/routing/README.md
+++ b/_examples/routing/README.md
@@ -383,6 +383,7 @@ import "github.com/kataras/iris"
func main() {
app := iris.New()
+ // or app.Use(before) and app.Done(after).
app.Get("/", before, mainHandler, after)
app.Run(iris.Addr(":8080"))
}
@@ -433,18 +434,22 @@ import "github.com/kataras/iris"
func main() {
app := iris.New()
- // register the "before" handler as the first handler which will be executed
- // on all domain's routes.
- // or use the `UseGlobal` to register a middleware which will fire across subdomains.
- app.Use(before)
- // register the "after" handler as the last handler which will be executed
- // after all domain's routes' handler(s).
- app.Done(after)
// register our routes.
app.Get("/", indexHandler)
app.Get("/contact", contactHandler)
+ // Order of those calls doesn't matter, `UseGlobal` and `DoneGlobal`
+ // are applied to existing routes and future routes.
+ //
+ // Remember: the `Use` and `Done` are applied to the current party's and its children,
+ // so if we used the `app.Use/Don`e before the routes registration
+ // it would work like UseGlobal/DoneGlobal in this case, because the `app` is the root party.
+ //
+ // See `app.Party/PartyFunc` for more.
+ app.UseGlobal(before)
+ app.DoneGlobal(after)
+
app.Run(iris.Addr(":8080"))
}
diff --git a/_examples/routing/writing-a-middleware/globally/main.go b/_examples/routing/writing-a-middleware/globally/main.go
index 2093d854..b89ac7f1 100644
--- a/_examples/routing/writing-a-middleware/globally/main.go
+++ b/_examples/routing/writing-a-middleware/globally/main.go
@@ -6,16 +6,29 @@ func main() {
app := iris.New()
// register the "before" handler as the first handler which will be executed
// on all domain's routes.
- // or use the `UseGlobal` to register a middleware which will fire across subdomains.
- app.Use(before)
+ // Or use the `UseGlobal` to register a middleware which will fire across subdomains.
+ // app.Use(before)
// register the "after" handler as the last handler which will be executed
// after all domain's routes' handler(s).
- app.Done(after)
+ //
+ // Or use the `DoneGlobal` to append handlers that will be fired globally.
+ // app.Done(after)
// register our routes.
app.Get("/", indexHandler)
app.Get("/contact", contactHandler)
+ // Order of those calls doesn't matter, `UseGlobal` and `DoneGlobal`
+ // are applied to existing routes and future routes.
+ //
+ // Remember: the `Use` and `Done` are applied to the current party's and its children,
+ // so if we used the `app.Use/Don`e before the routes registration
+ // it would work like UseGlobal/DoneGlobal in this case, because the `app` is the root party.
+ //
+ // See `app.Party/PartyFunc` for more.
+ app.UseGlobal(before)
+ app.DoneGlobal(after)
+
app.Run(iris.Addr(":8080"))
}
@@ -43,7 +56,7 @@ func indexHandler(ctx iris.Context) {
ctx.HTML("Response
")
ctx.HTML("
Info: " + info)
- ctx.Next() // execute the "after" handler registered via `Done`.
+ ctx.Next() // execute the "after" handler registered via `DoneGlobal`.
}
func contactHandler(ctx iris.Context) {
@@ -52,5 +65,5 @@ func contactHandler(ctx iris.Context) {
// write something to the client as a response.
ctx.HTML("Contact
")
- ctx.Next() // execute the "after" handler registered via `Done`.
+ ctx.Next() // execute the "after" handler registered via `DoneGlobal`.
}
diff --git a/_examples/routing/writing-a-middleware/per-route/main.go b/_examples/routing/writing-a-middleware/per-route/main.go
index 3b5b8e17..38440561 100644
--- a/_examples/routing/writing-a-middleware/per-route/main.go
+++ b/_examples/routing/writing-a-middleware/per-route/main.go
@@ -4,7 +4,40 @@ import "github.com/kataras/iris"
func main() {
app := iris.New()
+ // or app.Use(before) and app.Done(after).
app.Get("/", before, mainHandler, after)
+
+ // Use registers a middleware(prepend handlers) to all party's, and its children that will be registered
+ // after.
+ //
+ // (`app` is the root children so those use and done handlers will be registered everywhere)
+ app.Use(func(ctx iris.Context) {
+ println(`before the party's routes and its children,
+but this is not applied to the '/' route
+because it's registered before the middleware, order matters.`)
+ ctx.Next()
+ })
+
+ app.Done(func(ctx iris.Context) {
+ println("this is executed always last, if the previous handler calls the `ctx.Next()`, it's the reverse of `.Use`")
+ message := ctx.Values().GetString("message")
+ println("message: " + message)
+ })
+
+ app.Get("/home", func(ctx iris.Context) {
+ ctx.HTML(" Home
")
+ ctx.Values().Set("message", "this is the home message, ip: "+ctx.RemoteAddr())
+ ctx.Next() // call the done handlers.
+ })
+
+ child := app.Party("/child")
+ child.Get("/", func(ctx iris.Context) {
+ ctx.Writef(`this is the localhost:8080/child route.
+All Use and Done handlers that are registered to the parent party,
+are applied here as well.`)
+ ctx.Next() // call the done handlers.
+ })
+
app.Run(iris.Addr(":8080"))
}
diff --git a/context/context.go b/context/context.go
index 541b1f42..dc3ecf80 100644
--- a/context/context.go
+++ b/context/context.go
@@ -26,7 +26,7 @@ import (
formbinder "github.com/iris-contrib/formBinder"
"github.com/json-iterator/go"
"github.com/microcosm-cc/bluemonday"
- "github.com/russross/blackfriday"
+ "gopkg.in/russross/blackfriday.v2"
"gopkg.in/yaml.v2"
"github.com/kataras/iris/core/errors"
diff --git a/core/maintenance/version.go b/core/maintenance/version.go
index f98c41ab..fd16b8d2 100644
--- a/core/maintenance/version.go
+++ b/core/maintenance/version.go
@@ -13,7 +13,7 @@ import (
const (
// Version is the string representation of the current local Iris Web Framework version.
- Version = "10.1.0"
+ Version = "10.2.0"
)
// CheckForUpdates checks for any available updates
diff --git a/core/router/api_builder.go b/core/router/api_builder.go
index 434e0474..da366245 100644
--- a/core/router/api_builder.go
+++ b/core/router/api_builder.go
@@ -85,10 +85,10 @@ type APIBuilder struct {
// even before the `middleware` handlers, and in the same time keep the order
// of handlers registration, so the same type of handlers are being called in order.
beginGlobalHandlers context.Handlers
- // the per-party routes registry (useful for `Done` and `UseGlobal` only)
- apiRoutes []*Route
- // the per-party done handlers, order
- // of handlers registration matters.
+
+ // the per-party done handlers, order matters.
+ doneHandlers context.Handlers
+ // global done handlers, order doesn't matter
doneGlobalHandlers context.Handlers
// the per-party
relativePath string
@@ -164,10 +164,8 @@ func (api *APIBuilder) Handle(method string, relativePath string, handlers ...co
// global begin handlers -> middleware that are registered before route registration
// -> handlers that are passed to this Handle function.
routeHandlers := joinHandlers(api.middleware, handlers)
- // -> done handlers after all
- if len(api.doneGlobalHandlers) > 0 {
- routeHandlers = append(routeHandlers, api.doneGlobalHandlers...) // register the done middleware, if any
- }
+ // -> done handlers
+ routeHandlers = joinHandlers(routeHandlers, api.doneHandlers)
// here we separate the subdomain and relative path
subdomain, path := splitSubdomainAndPath(fullpath)
@@ -178,14 +176,15 @@ func (api *APIBuilder) Handle(method string, relativePath string, handlers ...co
return nil
}
- // Add UseGlobal Handlers
+ // Add UseGlobal & DoneGlobal Handlers
r.use(api.beginGlobalHandlers)
+ r.done(api.doneGlobalHandlers)
// global
api.routes.register(r)
// per -party, used for done handlers
- api.apiRoutes = append(api.apiRoutes, r)
+ // api.apiRoutes = append(api.apiRoutes, r)
return r
}
@@ -270,6 +269,7 @@ func (api *APIBuilder) Party(relativePath string, handlers ...context.Handler) P
reporter: api.reporter,
// per-party/children
middleware: middleware,
+ doneHandlers: api.doneHandlers,
relativePath: fullpath,
}
}
@@ -379,22 +379,14 @@ func (api *APIBuilder) Use(handlers ...context.Handler) {
api.middleware = append(api.middleware, handlers...)
}
-// Done appends to the very end, Handler(s) to the current Party's routes and child routes
-// The difference from .Use is that this/or these Handler(s) are being always running last.
-func (api *APIBuilder) Done(handlers ...context.Handler) {
- for _, r := range api.routes.routes {
- r.done(handlers) // append the handlers to the existing routes
- }
- // set as done handlers for the next routes as well.
- api.doneGlobalHandlers = append(api.doneGlobalHandlers, handlers...)
-}
-
-// UseGlobal registers handlers that should run before all routes,
-// including all parties, subdomains
-// and other middleware that were registered before or will be after.
+// UseGlobal registers handlers that should run at the very beginning.
+// It prepends those handler(s) to all routes,
+// including all parties, subdomains.
// It doesn't care about call order, it will prepend the handlers to all
// existing routes and the future routes that may being registered.
//
+// The difference from `.DoneGLobal` is that this/or these Handler(s) are being always running first.
+// Use of `ctx.Next()` of those handler(s) is necessary to call the main handler or the next middleware.
// It's always a good practise to call it right before the `Application#Run` function.
func (api *APIBuilder) UseGlobal(handlers ...context.Handler) {
for _, r := range api.routes.routes {
@@ -404,6 +396,42 @@ func (api *APIBuilder) UseGlobal(handlers ...context.Handler) {
api.beginGlobalHandlers = append(api.beginGlobalHandlers, handlers...)
}
+// Done appends to the very end, Handler(s) to the current Party's routes and child routes.
+//
+// Call order matters, it should be called right before the routes that they care about these handlers.
+//
+// The difference from .Use is that this/or these Handler(s) are being always running last.
+func (api *APIBuilder) Done(handlers ...context.Handler) {
+ api.doneHandlers = append(api.doneHandlers, handlers...)
+}
+
+// DoneGlobal registers handlers that should run at the very end.
+// It appends those handler(s) to all routes,
+// including all parties, subdomains.
+// It doesn't care about call order, it will append the handlers to all
+// existing routes and the future routes that may being registered.
+//
+// The difference from `.UseGlobal` is that this/or these Handler(s) are being always running last.
+// Use of `ctx.Next()` at the previous handler is necessary.
+// It's always a good practise to call it right before the `Application#Run` function.
+func (api *APIBuilder) DoneGlobal(handlers ...context.Handler) {
+ for _, r := range api.routes.routes {
+ r.done(handlers) // append the handlers to the existing routes
+ }
+ // set as done handlers for the next routes as well.
+ api.doneGlobalHandlers = append(api.doneGlobalHandlers, handlers...)
+}
+
+// Reset removes all the begin and done handlers that may derived from the parent party via `Use` & `Done`,
+// note that the `Reset` will not reset the handlers that are registered via `UseGlobal` & `DoneGlobal`.
+//
+// Returns this Party.
+func (api *APIBuilder) Reset() Party {
+ api.middleware = api.middleware[0:0]
+ api.doneHandlers = api.doneHandlers[0:0]
+ return api
+}
+
// None registers an "offline" route
// see context.ExecRoute(routeName) and
// party.Routes().Online(handleResultRouteInfo, "GET") and
diff --git a/core/router/party.go b/core/router/party.go
index a8145f91..6f0e814e 100644
--- a/core/router/party.go
+++ b/core/router/party.go
@@ -53,17 +53,21 @@ type Party interface {
// this specific "subdomain".
//
// If called from a child party then the subdomain will be prepended to the path instead of appended.
- // So if app.Subdomain("admin.").Subdomain("panel.") then the result is: "panel.admin.".
+ // So if app.Subdomain("admin").Subdomain("panel") then the result is: "panel.admin.".
Subdomain(subdomain string, middleware ...context.Handler) Party
// Use appends Handler(s) to the current Party's routes and child routes.
// If the current Party is the root, then it registers the middleware to all child Parties' routes too.
Use(middleware ...context.Handler)
- // Done appends to the very end, Handler(s) to the current Party's routes and child routes
+ // Done appends to the very end, Handler(s) to the current Party's routes and child routes.
// The difference from .Use is that this/or these Handler(s) are being always running last.
Done(handlers ...context.Handler)
-
+ // Reset removes all the begin and done handlers that may derived from the parent party via `Use` & `Done`,
+ // note that the `Reset` will not reset the handlers that are registered via `UseGlobal` & `DoneGlobal`.
+ //
+ // Returns this Party.
+ Reset() Party
// Handle registers a route to the server's router.
// if empty method is passed then handler(s) are being registered to all methods, same as .Any.
//
diff --git a/core/router/router_handlers_order_test.go b/core/router/router_handlers_order_test.go
index 3bdc6422..a8951c7b 100644
--- a/core/router/router_handlers_order_test.go
+++ b/core/router/router_handlers_order_test.go
@@ -118,7 +118,7 @@ func TestMiddlewareByUseDoneAndUseGlobalDef(t *testing.T) {
testResponse(t, app, "/mypath")
}
-func TestMiddlewareByUseGlobalUseAndDoneDef(t *testing.T) {
+func TestMiddlewareByUseGlobalUseAndDoneGlobalDef(t *testing.T) {
app := iris.New()
app.UseGlobal(firstUseGlobalHandler)
@@ -127,7 +127,7 @@ func TestMiddlewareByUseGlobalUseAndDoneDef(t *testing.T) {
app.Get("/mypath", mainHandler)
- app.Done(firstDoneHandler, secondDoneHandler)
+ app.DoneGlobal(firstDoneHandler, secondDoneHandler)
testResponse(t, app, "/mypath")
}