Former-commit-id: 2eb94ec0f565b80790784ac55af024429384b3d3
This commit is contained in:
Gerasimos (Makis) Maropoulos 2018-02-08 14:04:39 +02:00
parent 5d62b5d428
commit 9cdae4ee67
18 changed files with 168 additions and 56 deletions

2
Gopkg.lock generated
View File

@ -158,7 +158,7 @@
version = "v1.0.0" version = "v1.0.0"
[[projects]] [[projects]]
name = "github.com/russross/blackfriday" name = "gopkg.in/russross/blackfriday.v2"
packages = ["."] packages = ["."]
revision = "cadec560ec52d93835bf2f15bd794700d3a2473b" revision = "cadec560ec52d93835bf2f15bd794700d3a2473b"
version = "v2.0.0" version = "v2.0.0"

View File

@ -55,8 +55,8 @@
name = "github.com/microcosm-cc/bluemonday" name = "github.com/microcosm-cc/bluemonday"
[[constraint]] [[constraint]]
name = "github.com/russross/blackfriday" branch = "v2"
version = "2.0.0" name = "gopkg.in/russross/blackfriday.v2"
[[constraint]] [[constraint]]
branch = "master" branch = "master"

View File

@ -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. **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 # Tu, 06 February 2018 | v10.1.0
New Features: New Features:

View File

@ -17,9 +17,13 @@
**Πώς να αναβαθμίσετε**: Ανοίξτε την γραμμή εντολών σας και εκτελέστε αυτήν την εντολή: `go get -u github.com/kataras/iris` ή αφήστε το αυτόματο updater να το κάνει αυτό για σας. **Πώς να αναβαθμίσετε**: Ανοίξτε την γραμμή εντολών σας και εκτελέστε αυτήν την εντολή: `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 # 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 # Tu, 16 January 2018 | v10.0.2

View File

@ -17,6 +17,10 @@
**如何升级**: 打开命令行执行以下命令: `go get -u github.com/kataras/iris` 或者等待自动更新。 **如何升级**: 打开命令行执行以下命令: `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 版本更新 # 2018 2月6号 | v10.1.0 版本更新
新特性: 新特性:

View File

@ -2,7 +2,7 @@
<img align="right" width="169px" src="https://iris-go.com/images/icon.svg?v=a" title="logo created by @merry.dii" /> <img align="right" width="169px" src="https://iris-go.com/images/icon.svg?v=a" title="logo created by @merry.dii" />
[![build status](https://img.shields.io/travis/kataras/iris/master.svg?style=flat-square)](https://travis-ci.org/kataras/iris)<!-- [![release](https://img.shields.io/github/release/kataras/iris.svg?style=flat-square)](https://github.com/kataras/iris/releases)--> [![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)<!--[![github closed issues](https://img.shields.io/github/issues-closed-raw/kataras/iris.svg?style=flat-square)](https://github.com/kataras/iris/issues?q=is%3Aissue+is%3Aclosed)--> [![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)<!-- [![release](https://img.shields.io/github/release/kataras/iris.svg?style=flat-square)](https://github.com/kataras/iris/releases)--> [![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)<!--[![github closed issues](https://img.shields.io/github/issues-closed-raw/kataras/iris.svg?style=flat-square)](https://github.com/kataras/iris/issues?q=is%3Aissue+is%3Aclosed)--> [![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. Iris is a fast, simple yet fully featured and very efficient web framework for Go.
@ -106,7 +106,7 @@ _Updated at: [Tuesday, 21 November 2017](_benchmarks/README_UNIX.md)_
## Support ## 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) - 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) - 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)

View File

@ -2,7 +2,7 @@
<img align="right" width="169px" src="https://iris-go.com/images/icon.svg?v=a" title="logo created by @merry.dii" /> <img align="right" width="169px" src="https://iris-go.com/images/icon.svg?v=a" title="logo created by @merry.dii" />
[![build status](https://img.shields.io/travis/kataras/iris/master.svg?style=flat-square)](https://travis-ci.org/kataras/iris)<!-- [![release](https://img.shields.io/github/release/kataras/iris.svg?style=flat-square)](https://github.com/kataras/iris/releases)--> [![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)<!--[![github closed issues](https://img.shields.io/github/issues-closed-raw/kataras/iris.svg?style=flat-square)](https://github.com/kataras/iris/issues?q=is%3Aissue+is%3Aclosed)--> [![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)<!-- [![release](https://img.shields.io/github/release/kataras/iris.svg?style=flat-square)](https://github.com/kataras/iris/releases)--> [![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)<!--[![github closed issues](https://img.shields.io/github/issues-closed-raw/kataras/iris.svg?style=flat-square)](https://github.com/kataras/iris/issues?q=is%3Aissue+is%3Aclosed)--> [![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. Το 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) - Μήπως τυχαίνει να βρήκατε κάποιο bug; Δημοσιεύστε το στα [github issues](https://github.com/kataras/iris/issues)
- Έχετε οποιεσδήποτε ερωτήσεις ή πρέπει να μιλήσετε με κάποιον έμπειρο για την επίλυση ενός προβλήματος σε πραγματικό χρόνο; Ελάτε μαζί μας στην [συνομιλία κοινότητας](https://chat.iris-go.com) - Έχετε οποιεσδήποτε ερωτήσεις ή πρέπει να μιλήσετε με κάποιον έμπειρο για την επίλυση ενός προβλήματος σε πραγματικό χρόνο; Ελάτε μαζί μας στην [συνομιλία κοινότητας](https://chat.iris-go.com)
- Συμπληρώστε την αναφορά εμπειρίας χρήστη κάνοντας κλικ [εδώ](https://docs.google.com/forms/d/e/1FAIpQLSdCxZXPANg_xHWil4kVAdhmh7EBBHQZ_4_xSZVDL-oCC_z5pA/viewform?usp=sf_link) - Συμπληρώστε την αναφορά εμπειρίας χρήστη κάνοντας κλικ [εδώ](https://docs.google.com/forms/d/e/1FAIpQLSdCxZXPANg_xHWil4kVAdhmh7EBBHQZ_4_xSZVDL-oCC_z5pA/viewform?usp=sf_link)

View File

@ -2,7 +2,7 @@
<img align="right" width="169px" src="https://iris-go.com/images/icon.svg?v=a" title="logo created by @merry.dii" /> <img align="right" width="169px" src="https://iris-go.com/images/icon.svg?v=a" title="logo created by @merry.dii" />
[![build status](https://img.shields.io/travis/kataras/iris/master.svg?style=flat-square)](https://travis-ci.org/kataras/iris)<!-- [![release](https://img.shields.io/github/release/kataras/iris.svg?style=flat-square)](https://github.com/kataras/iris/releases)--> [![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)<!--[![github closed issues](https://img.shields.io/github/issues-closed-raw/kataras/iris.svg?style=flat-square)](https://github.com/kataras/iris/issues?q=is%3Aissue+is%3Aclosed)--> [![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)<!-- [![release](https://img.shields.io/github/release/kataras/iris.svg?style=flat-square)](https://github.com/kataras/iris/releases)--> [![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)<!--[![github closed issues](https://img.shields.io/github/issues-closed-raw/kataras/iris.svg?style=flat-square)](https://github.com/kataras/iris/issues?q=is%3Aissue+is%3Aclosed)--> [![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. 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) - Вы случайно обнаружили ошибку? Опубликуйте ее на [Github вопросы](https://github.com/kataras/iris/issues)
- У Вас есть какие-либо вопросы или Вам нужно поговорить с кем-то, кто бы смог решить Вашу проблему в режиме реального времени? Присоединяйтесь к нам в [чате сообщества](https://chat.iris-go.com) - У Вас есть какие-либо вопросы или Вам нужно поговорить с кем-то, кто бы смог решить Вашу проблему в режиме реального времени? Присоединяйтесь к нам в [чате сообщества](https://chat.iris-go.com)
- Заполните наш отчет о пользовательском опыте на основе формы, нажав [здесь](https://docs.google.com/forms/d/e/1FAIpQLSdCxZXPANg_xHWil4kVAdhmh7EBBHQZ_4_xSZVDL-oCC_z5pA/viewform?usp=sf_link) - Заполните наш отчет о пользовательском опыте на основе формы, нажав [здесь](https://docs.google.com/forms/d/e/1FAIpQLSdCxZXPANg_xHWil4kVAdhmh7EBBHQZ_4_xSZVDL-oCC_z5pA/viewform?usp=sf_link)

View File

@ -2,7 +2,7 @@
<img align="right" width="169px" src="https://iris-go.com/images/icon.svg?v=a" title="logo created by @merry.dii" /> <img align="right" width="169px" src="https://iris-go.com/images/icon.svg?v=a" title="logo created by @merry.dii" />
[![build status](https://img.shields.io/travis/kataras/iris/master.svg?style=flat-square)](https://travis-ci.org/kataras/iris)<!-- [![release](https://img.shields.io/github/release/kataras/iris.svg?style=flat-square)](https://github.com/kataras/iris/releases)--> [![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)<!--[![github closed issues](https://img.shields.io/github/issues-closed-raw/kataras/iris.svg?style=flat-square)](https://github.com/kataras/iris/issues?q=is%3Aissue+is%3Aclosed)--> [![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)<!-- [![release](https://img.shields.io/github/release/kataras/iris.svg?style=flat-square)](https://github.com/kataras/iris/releases)--> [![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)<!--[![github closed issues](https://img.shields.io/github/issues-closed-raw/kataras/iris.svg?style=flat-square)](https://github.com/kataras/iris/issues?q=is%3Aissue+is%3Aclosed)--> [![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开发框架。 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) - 你碰巧找到了一个错误? 请提交 [github issues](https://github.com/kataras/iris/issues)
- 您是否有任何疑问或需要与有经验的人士交谈以实时解决问题? [加入我们的聊天](https://chat.iris-go.com) - 您是否有任何疑问或需要与有经验的人士交谈以实时解决问题? [加入我们的聊天](https://chat.iris-go.com)
- [点击这里完成我们基于表单的用户体验报告](https://docs.google.com/forms/d/e/1FAIpQLSdCxZXPANg_xHWil4kVAdhmh7EBBHQZ_4_xSZVDL-oCC_z5pA/viewform?usp=sf_link) - [点击这里完成我们基于表单的用户体验报告](https://docs.google.com/forms/d/e/1FAIpQLSdCxZXPANg_xHWil4kVAdhmh7EBBHQZ_4_xSZVDL-oCC_z5pA/viewform?usp=sf_link)

View File

@ -1 +1 @@
10.1.0:https://github.com/kataras/iris/blob/master/HISTORY.md#tu-06-february-2018--v1010 10.2.0:https://github.com/kataras/iris/blob/master/HISTORY.md#th-08-february-2018--v1020

View File

@ -383,6 +383,7 @@ import "github.com/kataras/iris"
func main() { func main() {
app := iris.New() app := iris.New()
// or app.Use(before) and app.Done(after).
app.Get("/", before, mainHandler, after) app.Get("/", before, mainHandler, after)
app.Run(iris.Addr(":8080")) app.Run(iris.Addr(":8080"))
} }
@ -433,18 +434,22 @@ import "github.com/kataras/iris"
func main() { func main() {
app := iris.New() 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. // register our routes.
app.Get("/", indexHandler) app.Get("/", indexHandler)
app.Get("/contact", contactHandler) 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")) app.Run(iris.Addr(":8080"))
} }

View File

@ -6,16 +6,29 @@ func main() {
app := iris.New() app := iris.New()
// register the "before" handler as the first handler which will be executed // register the "before" handler as the first handler which will be executed
// on all domain's routes. // on all domain's routes.
// or use the `UseGlobal` to register a middleware which will fire across subdomains. // Or use the `UseGlobal` to register a middleware which will fire across subdomains.
app.Use(before) // app.Use(before)
// register the "after" handler as the last handler which will be executed // register the "after" handler as the last handler which will be executed
// after all domain's routes' handler(s). // 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. // register our routes.
app.Get("/", indexHandler) app.Get("/", indexHandler)
app.Get("/contact", contactHandler) 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")) app.Run(iris.Addr(":8080"))
} }
@ -43,7 +56,7 @@ func indexHandler(ctx iris.Context) {
ctx.HTML("<h1>Response</h1>") ctx.HTML("<h1>Response</h1>")
ctx.HTML("<br/> Info: " + info) ctx.HTML("<br/> 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) { func contactHandler(ctx iris.Context) {
@ -52,5 +65,5 @@ func contactHandler(ctx iris.Context) {
// write something to the client as a response. // write something to the client as a response.
ctx.HTML("<h1>Contact</h1>") ctx.HTML("<h1>Contact</h1>")
ctx.Next() // execute the "after" handler registered via `Done`. ctx.Next() // execute the "after" handler registered via `DoneGlobal`.
} }

View File

@ -4,7 +4,40 @@ import "github.com/kataras/iris"
func main() { func main() {
app := iris.New() app := iris.New()
// or app.Use(before) and app.Done(after).
app.Get("/", before, mainHandler, 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("<h1> Home </h1>")
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")) app.Run(iris.Addr(":8080"))
} }

View File

@ -26,7 +26,7 @@ import (
formbinder "github.com/iris-contrib/formBinder" formbinder "github.com/iris-contrib/formBinder"
"github.com/json-iterator/go" "github.com/json-iterator/go"
"github.com/microcosm-cc/bluemonday" "github.com/microcosm-cc/bluemonday"
"github.com/russross/blackfriday" "gopkg.in/russross/blackfriday.v2"
"gopkg.in/yaml.v2" "gopkg.in/yaml.v2"
"github.com/kataras/iris/core/errors" "github.com/kataras/iris/core/errors"

View File

@ -13,7 +13,7 @@ import (
const ( const (
// Version is the string representation of the current local Iris Web Framework version. // 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 // CheckForUpdates checks for any available updates

View File

@ -85,10 +85,10 @@ type APIBuilder struct {
// even before the `middleware` handlers, and in the same time keep the order // 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. // of handlers registration, so the same type of handlers are being called in order.
beginGlobalHandlers context.Handlers beginGlobalHandlers context.Handlers
// the per-party routes registry (useful for `Done` and `UseGlobal` only)
apiRoutes []*Route // the per-party done handlers, order matters.
// the per-party done handlers, order doneHandlers context.Handlers
// of handlers registration matters. // global done handlers, order doesn't matter
doneGlobalHandlers context.Handlers doneGlobalHandlers context.Handlers
// the per-party // the per-party
relativePath string 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 // global begin handlers -> middleware that are registered before route registration
// -> handlers that are passed to this Handle function. // -> handlers that are passed to this Handle function.
routeHandlers := joinHandlers(api.middleware, handlers) routeHandlers := joinHandlers(api.middleware, handlers)
// -> done handlers after all // -> done handlers
if len(api.doneGlobalHandlers) > 0 { routeHandlers = joinHandlers(routeHandlers, api.doneHandlers)
routeHandlers = append(routeHandlers, api.doneGlobalHandlers...) // register the done middleware, if any
}
// here we separate the subdomain and relative path // here we separate the subdomain and relative path
subdomain, path := splitSubdomainAndPath(fullpath) subdomain, path := splitSubdomainAndPath(fullpath)
@ -178,14 +176,15 @@ func (api *APIBuilder) Handle(method string, relativePath string, handlers ...co
return nil return nil
} }
// Add UseGlobal Handlers // Add UseGlobal & DoneGlobal Handlers
r.use(api.beginGlobalHandlers) r.use(api.beginGlobalHandlers)
r.done(api.doneGlobalHandlers)
// global // global
api.routes.register(r) api.routes.register(r)
// per -party, used for done handlers // per -party, used for done handlers
api.apiRoutes = append(api.apiRoutes, r) // api.apiRoutes = append(api.apiRoutes, r)
return r return r
} }
@ -270,6 +269,7 @@ func (api *APIBuilder) Party(relativePath string, handlers ...context.Handler) P
reporter: api.reporter, reporter: api.reporter,
// per-party/children // per-party/children
middleware: middleware, middleware: middleware,
doneHandlers: api.doneHandlers,
relativePath: fullpath, relativePath: fullpath,
} }
} }
@ -379,22 +379,14 @@ func (api *APIBuilder) Use(handlers ...context.Handler) {
api.middleware = append(api.middleware, handlers...) api.middleware = append(api.middleware, handlers...)
} }
// Done appends to the very end, Handler(s) to the current Party's routes and child routes // UseGlobal registers handlers that should run at the very beginning.
// The difference from .Use is that this/or these Handler(s) are being always running last. // It prepends those handler(s) to all routes,
func (api *APIBuilder) Done(handlers ...context.Handler) { // including all parties, subdomains.
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.
// It doesn't care about call order, it will prepend the handlers to all // It doesn't care about call order, it will prepend the handlers to all
// existing routes and the future routes that may being registered. // 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. // It's always a good practise to call it right before the `Application#Run` function.
func (api *APIBuilder) UseGlobal(handlers ...context.Handler) { func (api *APIBuilder) UseGlobal(handlers ...context.Handler) {
for _, r := range api.routes.routes { for _, r := range api.routes.routes {
@ -404,6 +396,42 @@ func (api *APIBuilder) UseGlobal(handlers ...context.Handler) {
api.beginGlobalHandlers = append(api.beginGlobalHandlers, handlers...) 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 // None registers an "offline" route
// see context.ExecRoute(routeName) and // see context.ExecRoute(routeName) and
// party.Routes().Online(handleResultRouteInfo, "GET") and // party.Routes().Online(handleResultRouteInfo, "GET") and

View File

@ -53,17 +53,21 @@ type Party interface {
// this specific "subdomain". // this specific "subdomain".
// //
// If called from a child party then the subdomain will be prepended to the path instead of appended. // 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 Subdomain(subdomain string, middleware ...context.Handler) Party
// Use appends Handler(s) to the current Party's routes and child routes. // 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. // If the current Party is the root, then it registers the middleware to all child Parties' routes too.
Use(middleware ...context.Handler) 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. // The difference from .Use is that this/or these Handler(s) are being always running last.
Done(handlers ...context.Handler) 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. // 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. // if empty method is passed then handler(s) are being registered to all methods, same as .Any.
// //

View File

@ -118,7 +118,7 @@ func TestMiddlewareByUseDoneAndUseGlobalDef(t *testing.T) {
testResponse(t, app, "/mypath") testResponse(t, app, "/mypath")
} }
func TestMiddlewareByUseGlobalUseAndDoneDef(t *testing.T) { func TestMiddlewareByUseGlobalUseAndDoneGlobalDef(t *testing.T) {
app := iris.New() app := iris.New()
app.UseGlobal(firstUseGlobalHandler) app.UseGlobal(firstUseGlobalHandler)
@ -127,7 +127,7 @@ func TestMiddlewareByUseGlobalUseAndDoneDef(t *testing.T) {
app.Get("/mypath", mainHandler) app.Get("/mypath", mainHandler)
app.Done(firstDoneHandler, secondDoneHandler) app.DoneGlobal(firstDoneHandler, secondDoneHandler)
testResponse(t, app, "/mypath") testResponse(t, app, "/mypath")
} }