Former-commit-id: 4e30bf6a74acb7d463c7fcf1e9e08ca3147117a7
This commit is contained in:
Gerasimos (Makis) Maropoulos 2017-10-06 08:23:03 +03:00
parent 4fb78bbcd9
commit e5600fcf0d
18 changed files with 682 additions and 419 deletions

View File

@ -18,6 +18,17 @@ 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`.
# Fr, 06 October 2017 | v8.4.5
- Badger team added support for transactions [yesterday](https://github.com/dgraph-io/badger/commit/06242925c2f2a5e73dc688e9049004029dd7f9f7), therefore the [badger session database](sessions/sessiondb/badger) is updated via https://github.com/kataras/iris/commit/0b48927562a2202809a7674ebedb738dc3da57e8.
- MVC: Support more than one path parameters with a single `By`, when the `By` keyword is the last word and the func's input arguments are more than one i.e `GetBy(name string, age int)`, note that you can still use the older way of doing this; `GetByBy(string, int)`. It's an enhancement of the https://github.com/kataras/iris/issues/751 feature request.
- MVC: Give controllers the ability to auto-initialize themselves by `OnActivate` func derives from the new [ActivateListener](mvc/activator/activate_listener.go) interface, this can be used to perform any custom actions when the app registers the supported Controllers. See [mvc/session_controller.go](mvc/session_controller.go) for a good use case.
- errors.Reporter.AddErr returns true if the error is added to the stack, otherwise false.
- @ZaniaDeveloper fixed https://github.com/kataras/iris/issues/778 with PR: https://github.com/kataras/iris/pull/779.
- Add `StatusSeeOther` at [mvc login example](https://github.com/kataras/iris/blob/master/_examples/mvc/login/user/controller.go#L53) for Redirection, reported by @motecshine at https://github.com/kataras/iris/issues/777.
- Fix `DisableVersionChecker` configuration field is not being passed correctly when it was true via `iris.Run(..., iris.WithConfiguration{DisableVersionChecker:true, ...})` call.
# Su, 01 October 2017 | v8.4.4
- Fix https://github.com/kataras/iris/issues/762 reported by @xkylsoft

469
README.md
View File

@ -1,43 +1,49 @@
<!-- # ![Logo created by @santoshanand](logo_white_35_24.png) Iris -->
## 03, October 2017 | Iris User Experience Report
Be part of the **first** Iris User Experience Report by submitting a simple form, it won't take more than **5 minutes**.
The form contains some questions that you may need to answer in order to learn more about you; learning more about you helps us to serve you with the best possible way!
https://docs.google.com/forms/d/e/1FAIpQLSdCxZXPANg_xHWil4kVAdhmh7EBBHQZ_4_xSZVDL-oCC_z5pA/viewform?usp=sf_link
<a href="https://docs.google.com/forms/d/e/1FAIpQLSdCxZXPANg_xHWil4kVAdhmh7EBBHQZ_4_xSZVDL-oCC_z5pA/viewform?usp=sf_link"><img src="https://iris-go.com/public/images/user_experience_report.png" alt="Iris User Experience Report - Header" width="400"></a>
<p align="center">
<img src="iris_the_new_machine.gif">
</p>
# ![Logo created by @santoshanand](logo_white_35_24.png) Iris
Iris is a fast, simple and efficient micro web framework for Go. It provides a beautifully expressive and easy to use foundation for your next website, API, or distributed app.
We have no doubt you will able to find other web frameworks written in Go
and even put up a real fight to learn and use them for quite some time but
make no mistake, sooner or later you will be using Iris, not because of the ergonomic, high-performant solution that it provides but its well-documented unique features, as these will transform you to a real rockstar geek.
### About our User Experience Report
No matter what you're trying to build, Iris covers
every type of application, from micro services to large monolithic web applications.
It's actually the best piece of software for back-end web developers
you can find online.
Three days ago, _at 03 October_, we announced the first [Iris User Experience form-based Report](https://docs.google.com/forms/d/e/1FAIpQLSdCxZXPANg_xHWil4kVAdhmh7EBBHQZ_4_xSZVDL-oCC_z5pA/viewform?usp=sf_link) to let us learn more about you and any issues that troubles you with Iris (if any).
Iris may have reached version 8, but we're not stopping there. We have many feature ideas on our board that we're anxious to add and other innovative web development solutions that we're planning to build into Iris.
At overall, the results (so far) are very promising, high number of participations and the answers to the questions are near to the green feedback we were receiving over the past months from Gophers worldwide via our [rocket chat](https://chat.iris-go.com) and [author's twitter](https://twitter.com/makismaropoulos). **If you didn't complete the form yet, [please do so](https://docs.google.com/forms/d/e/1FAIpQLSdCxZXPANg_xHWil4kVAdhmh7EBBHQZ_4_xSZVDL-oCC_z5pA/viewform?usp=sf_link) as soon as possible!**
Iris was built on top of the the [net/http](https://golang.org/pkg/net/http/) package, we own many thanks to [Brad Fitzpatrick](https://github.com/bradfitz) for that.
However, as everything in life; nothing goes as expected, people are strange, we programmers even more. The last part of the form has a text area which participiations can add any "questions or comments", there we saw one comment that surprised me, in the bad sense. We respect all individual singularities the same, we do not discriminate between people. The data are anonymous, so the only place to answer to that person is, _surprisingly_, here!
If you're coming from <a href="https://nodejs.org/en/">Node.js</a> world, this is the <a href="https://github.com/expressjs/express">expressjs</a> equivalent for the <a href="https://golang.org">Go Programming Language.</a><br/>
<details>
<summary>"I admire your dedication to iris and I am in love with its speed..."</summary>
**Accelerated** by [KeyCDN](https://www.keycdn.com/), A Simple, Fast and Reliable CDN.
The comment was "I admire your dedication to iris and I am in love with its speed but.. I've read some things on that blog and blablabla..." you get the point, at the first we were happy and suddenly we saw that "but... I've" and we broke xD.
**We are developing** this project using the best code editor for Golang; [Visual Studio Code](https://code.visualstudio.com/) supported by [Microsoft](https://www.microsoft.com).
My answer to this is clear in simple words so that anyone can understand; Did you really believed those unsubstantial things even if you could take some time off to read the source code?🤔
[Star](https://github.com/kataras/iris/stargazers) and watch this github repository to stay up to date.
Iris was the one of the top github trending projects written in Go Programming Language for the 2016 and the most trending web framework in the globe. We couldn't even imagine that we will be the receiver of countless "[thank you for iris, finally a web framework I can work on](https://twitter.com/_mgale/status/818591490305761280)" comments from hundreds strangers around the globe!
Please do research before reading and assimilate everything, those blog spots are not always telling the whole truth, they are not so innocent :)
Especially those from that kid which do not correspond to reality;
```go
/* start */
```
First of all, that article **is reffering 1.5 years ago**, to pretend that this article speaks for the present is hilariously ridiculous! Iris is on version 8 now and it's not a router any more, it's a fully featured web framework with its own ecosystem.
1. Iris does NOT use any third-party code inside it, like "httprouter" or "fasthttp". Just navigate to the source code. If you care about historical things you can search the project but it doesn't matter because the internal implementation of Iris changed a lot of times, a lot more than its public API changes:P.
2. Iris makes use of its own routing mechanisms with a unique **language interpreter** in order to serve even the most demanding of us `/user/{id:int min(2)}`, `/alphabetical/{param:string regexp(^[a-zA-Z ]+$)}` et cetera.
3. Iris has its own unique MVC architectural parser with hurt-breaking performance.
4. Was it possible to do all those things and [much more](_examples) before Iris? Exaclty. Iris offers you all these for free, plus the unmatched performance.
5. Iris is the result of hundreds(or thousands(?)) of hours of **FREE and UNPAID** work. There are people who actually found a decent job because of Iris. Thousands of Gophers are watching or/and helping to make Iris even better, the silent majority loves Iris even more.
That 23 years old, inhibited boy, who published that post had played you with the most immoral way! Reading the Iris' source code doesn't cost you a thing! Iris is free to use for everyone, Iris is an open-source software, no hidden spots. **Don't stuck on the past, get over that, Iris has succeed, move on now.**
```go
/* end */
```
</details>
_Psst_, we've produced a small video about your feelings regrating to Iris! You can watch the whole video at https://www.youtube.com/watch?v=jGx0LkuUs4A.
<!-- [![total used by](https://iris-go.com/graph?style=flat-square)](https://iris-go.com/graph) -->
[![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)
[![github issues](https://img.shields.io/github/issues/kataras/iris.svg?style=flat-square)](https://github.com/kataras/iris/issues?q=is%3Aopen+is%3Aissue)
@ -46,88 +52,11 @@ If you're coming from <a href="https://nodejs.org/en/">Node.js</a> world, this i
[![view examples](https://img.shields.io/badge/learn%20by-examples-0077b3.svg?style=flat-square)](https://github.com/kataras/iris/tree/master/_examples)
[![chat](https://img.shields.io/badge/community-%20chat-00BCD4.svg?style=flat-square)](https://kataras.rocket.chat/channel/iris)
<!-- has issues, the img.shields.io's API is problematic for this resource: [![issue stats](https://img.shields.io/issuestats/i/github/kataras/iris.svg?style=flat-square)](https://github.com/kataras/iris/issues?q=is%3Aissue+is%3Aclosed) -->
<!-- [![godocs](https://img.shields.io/badge/godocs-8.x.x-0366d6.svg?style=flat-square)](https://godoc.org/github.com/kataras/iris) -->
![Iris vs .NET Core(C#) vs Node.js (Express)](https://iris-go.com/images/benchmark-new-gray.png)
<details>
<summary>Benchmarks from third-party source over the rest web frameworks</summary>
![Comparison with other frameworks](https://raw.githubusercontent.com/smallnest/go-web-framework-benchmark/4db507a22c964c9bc9774c5b31afdc199a0fe8b7/benchmark.png)
</details>
_Updated at: [Friday, 29 September 2017](_benchmarks)_
[![Iris vs .NET Core(C#) vs Node.js (Express)](https://iris-go.com/images/benchmark-new-gray.png)](_benchmarks)
</p>
### [🎗️](#-people) Legends
Help this project to continue deliver awesome and unique features with the higher code quality as possible by donating any amount via [PayPal](https://www.paypal.me/kataras)!
| Name | Amount | Membership |
| -----------|--------|--------|
| [Juan Sebastián Suárez Valencia](https://github.com/Juanses) | 20 EUR | Bronze |
| [Bob Lee](https://github.com/li3p) | 20 EUR | Bronze |
| [Celso Luiz](https://github.com/celsosz) | 50 EUR | **Silver** |
| [Ankur Srivastava](https://github.com/ansrivas) | 20 EUR | Bronze |
| [Damon Zhao](https://github.com/se77en) | 20 EUR | Bronze |
| [Exponity - Tech Company](https://github.com/exponity) | 30 EUR | Bronze |
| [Thomas Fritz](https://github.com/thomasfr) | 25 EUR | Bronze |
| [Thanos V.](http://mykonosbiennale.com/) | 20 EUR | Bronze |
| [George Opritescu](https://github.com/International) | 20 EUR | Bronze |
| [Lex Tang](https://github.com/lexrus) | 20 EUR | Bronze |
| [Bill Q.](https://github.com/hiveminded) | 600 EUR | **Gold** |
| [Conrad Steenberg](https://github.com/hengestone) | 25 EUR | Bronze |
_Psst_, we've produced a small video about your feelings regrating to Iris! You can watch the video at https://www.youtube.com/watch?v=jGx0LkuUs4A.
### 📑 Table of contents
* [Installation](#-installation)
* [Latest changes](https://github.com/kataras/iris/blob/master/HISTORY.md#su-01-october-2017--v844)
* [Learn](#-learn)
* [Structuring](_examples/#structuring)
* [HTTP Listening](_examples/#http-listening)
* [Configuration](_examples/#configuration)
* [Routing, Grouping, Dynamic Path Parameters, "Macros" and Custom Context](_examples/#routing-grouping-dynamic-path-parameters-macros-and-custom-context)
* [MVC (Model View Controller)](_examples/#mvc) **NEW**
* [Subdomains](_examples/#subdomains)
* [Wrap `http.Handler/HandlerFunc`](_examples/#convert-httphandlerhandlerfunc)
* [View](_examples/#view)
* [Authentication](_examples/#authentication)
* [File Server](_examples/#file-server)
* [How to Read from `context.Request() *http.Request`](_examples/#how-to-read-from-contextrequest-httprequest)
* [How to Write to `context.ResponseWriter() http.ResponseWriter`](_examples/#how-to-write-to-contextresponsewriter-httpresponsewriter)
* [Test](_examples/#testing)
* [Cache](_examples/#caching)
* [Sessions](_examples/#sessions)
* [Websockets](_examples/#websockets)
* [Miscellaneous](_examples/#miscellaneous)
* [POC: Convert the medium-sized project "Parrot" from native to Iris](https://github.com/iris-contrib/parrot)
* [POC: Isomorphic react/hot reloadable/redux/css-modules starter kit](https://github.com/kataras/iris-starter-kit)
* [Typescript Automation Tools](typescript/#table-of-contents)
* [Tutorial: Online Visitors](_examples/tutorial/online-visitors)
* [Tutorial: Caddy](_examples/tutorial/caddy)
* [Tutorial: DropzoneJS Uploader](_examples/tutorial/dropzonejs)
* [Middleware](middleware/)
* [Dockerize](https://github.com/iris-contrib/cloud-native-go)
* [Community & Support](#-community)
* [Blogs](https://iris-go.com/v8/blogs)
- [How to build a file upload form using DropzoneJS and Go](https://hackernoon.com/how-to-build-a-file-upload-form-using-dropzonejs-and-go-8fb9f258a991)
- [How to display existing files on server using DropzoneJS and Go](https://hackernoon.com/how-to-display-existing-files-on-server-using-dropzonejs-and-go-53e24b57ba19)
- [Iris Go vs .NET Core Kestrel in terms of HTTP performance](https://hackernoon.com/iris-go-vs-net-core-kestrel-in-terms-of-http-performance-806195dc93d5)
- [Go vs .NET Core in terms of HTTP performance](https://medium.com/@kataras/go-vs-net-core-in-terms-of-http-performance-7535a61b67b8)
- [Iris, a modular web framework](https://medium.com/@corebreaker/iris-web-cd684b4685c7)
- [Deploying a Iris Golang app in hasura](https://medium.com/@HasuraHQ/deploy-an-iris-golang-app-with-backend-apis-in-minutes-25a559bf530b)
- [How to Turn an Android Device into a Web Server](https://twitter.com/ThePracticalDev/status/892022594031017988)
- [A URL Shortener Service using Go, Iris and Bolt](https://medium.com/@kataras/a-url-shortener-service-using-go-iris-and-bolt-4182f0b00ae7)
- [Why I preferred Go over Node.js for simple Web Application](https://medium.com/@tigranbs/why-i-preferred-go-over-node-js-for-simple-web-application-d4a549e979b9)
* [Versioning](#-version)
* [People](#-people)
### 🚀 Installation
## Installation
The only requirement is the [Go Programming Language](https://golang.org/dl/), at least version 1.9.
@ -135,11 +64,15 @@ The only requirement is the [Go Programming Language](https://golang.org/dl/), a
$ go get -u github.com/kataras/iris
```
> _iris_ takes advantage of the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature. You get truly reproducible builds, as this method guards against upstream renames and deletes.
* Iris takes advantage of the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature. You get truly reproducible builds, as this method guards against upstream renames and deletes.
* [Latest changes](https://github.com/kataras/iris/blob/master/HISTORY.md#fr-06-october-2017--v845)
## Getting Started
```go
// file: main.go
package main
import "github.com/kataras/iris"
func main() {
@ -177,7 +110,7 @@ func main() {
}
```
> See all available path parameter types at: https://github.com/kataras/iris/blob/master/_examples/routing/dynamic-path/main.go#L31
> Learn more about path parameter's types by clicking [here](https://github.com/kataras/iris/blob/master/_examples/routing/dynamic-path/main.go#L31).
```html
<!-- file: ./views/hello.html -->
@ -191,305 +124,89 @@ func main() {
</html>
```
```sh
```sh
$ go run main.go
> Now listening on: http://localhost:8080
> Application started. Press CTRL+C to shut down.
```
> Examples and docs are updated to Go 1.9, please refer to that [section](https://github.com/kataras/iris/blob/master/faq.md#type-aliases) before anything else.
<details>
<summary>Hello World with Go 1.8</summary>
Iris declares all of its type alias at the same file in order to be easy to be discovered.
> If you just upgraded to go 1.9 from 1.8 you can always search for a compatible type alias at the [context.go](context.go) file and opposite, if you use go 1.8 and you're new to Iris you can see [that](context.go) file to see the compatible packages.
If Go 1.8 remains the basic host for your go apps then you should declare and use the `github.com/kataras/iris/context` package on your source file's imports statement.
### Quick MVC Tutorial
```go
package main
import (
"github.com/kataras/iris"
"github.com/kataras/iris/context"
"github.com/kataras/iris"
"github.com/kataras/iris/mvc"
)
func main() {
app := iris.New()
app.RegisterView(iris.HTML("./templates", ".html"))
app.Get("/", func(ctx context.Context) {
ctx.ViewData("message", "Hello world!")
ctx.View("hello.html")
})
app.Run(iris.Addr(":8080"))
}
```
</details>
<details>
<summary>Fan of the MVC Architectural Pattern? Click here</summary>
```go
package main
import "github.com/kataras/iris"
func main() {
app := iris.New()
app.RegisterView(iris.HTML("./views", ".html"))
app.Controller("/", new(Controller))
app.Controller("/helloworld", new(HelloWorldController))
app.Run(iris.Addr(":8080"))
app.Run(iris.Addr("localhost:8080"))
}
type Controller struct {
iris.Controller
type HelloWorldController struct {
mvc.Controller
// [ your fields here ]
// Request lifecycle data
// Models
// Database
// Global properties
}
// Method: GET
// Resource: http://localhost:8080
func (c *Controller) Get() {
c.Data["message"] = "Hello world!"
c.Tmpl = "hello.html"
//
// GET: /helloworld
func (c *HelloWorldController) Get() {
c.Ctx.Text("This is my default action...")
}
// Method: GET
// Resource: http://localhost:8080/user/42
func (c *Controller) GetUserBy(id int64) {
c.Ctx.Writef("User ID: %d", id)
//
// GET: /helloworld/welcome
func (c *HelloWorldController) GetWelcome() {
c.Ctx.HTML("This is the <b>GetWelcome</b> action func...")
}
//
// GET: /helloworld/welcome/{name:string}/{numTimes:int}
func (c *HelloWorldController) GetWelcomeBy(name string, numTimes int) {
c.Ctx.Writef("Hello %s, NumTimes is: %d", name, numTimes)
}
```
</details>
> The [_examples/mvc](_examples/mvc) and [mvc/controller_test.go](https://github.com/kataras/iris/blob/master/mvc/controller_test.go) files explain each feature with simple paradigms, they show how you can take advandage of the Iris MVC Binder, Iris MVC Models and many more...
<details>
<summary>Why a new web framework</summary>
Every `exported` func prefixed with an HTTP Method(`Get`, `Post`, `Put`, `Delete`...) in a controller is callable as an HTTP endpoint. In the sample above, all funcs writes a string to the response. Note the comments preceding each method.
### Why
An HTTP endpoint is a targetable URL in the web application, such as `http://localhost:8080/helloworld`, and combines the protocol used: HTTP, the network location of the web server (including the TCP port): `localhost:8080` and the target URI `/helloworld`.
Go is a great technology stack for building scalable, web-based, back-end systems for web
applications.
The first comment states this is an [HTTP GET](https://www.w3schools.com/tags/ref_httpmethods.asp) method that is invoked by appending "/helloworld" to the base URL. The second comment specifies an [HTTP GET](https://www.w3schools.com/tags/ref_httpmethods.asp) method that is invoked by appending "/helloworld/welcome/" to the URL.
When you think about building web applications and web APIs, or simply building HTTP servers in Go, does your mind go to the standard net/http package?
Then you have to deal with some common situations like dynamic routing (a.k.a parameterized), security and authentication, real-time communication and many other issues that net/http doesn't solve.
Controller knows how to handle the "name" and "numTimes" at `GetWelcomeBy`, because of the `By` keyword, and builds the dynamic route without boilerplate; the third comment specifies an [HTTP GET](https://www.w3schools.com/tags/ref_httpmethods.asp) dynamic method that is invoked by any URL that starts with "/helloworld/welcome" and followed by two more path parts, the first one can accept any value and the second can accept only numbers, i,e: "http://localhost:8080/helloworld/welcome/golang/32719", otherwise a [404 Not Found HTTP Error](https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.5) will be sent to the client instead.
The net/http package is not complete enough to quickly build well-designed back-end web systems. When you realize this, you might be thinking along these lines:
## 😃 Do you like what you see so far?
- Ok, the net/http package doesn't suit me, but there are so many frameworks, which one will work for me?!
- Each one of them tells me that it is the best. I don't know what to do!
> Prepare yourself a cup of coffee, or tea, whatever enjoys you the most!
##### The truth
- [How to build a file upload form using DropzoneJS and Go](https://hackernoon.com/how-to-build-a-file-upload-form-using-dropzonejs-and-go-8fb9f258a991)
- [How to display existing files on server using DropzoneJS and Go](https://hackernoon.com/how-to-display-existing-files-on-server-using-dropzonejs-and-go-53e24b57ba19)
- [Iris Go vs .NET Core Kestrel in terms of HTTP performance](https://hackernoon.com/iris-go-vs-net-core-kestrel-in-terms-of-http-performance-806195dc93d5)
- [Go vs .NET Core in terms of HTTP performance](https://medium.com/@kataras/go-vs-net-core-in-terms-of-http-performance-7535a61b67b8)
- [Iris, a modular web framework](https://medium.com/@corebreaker/iris-web-cd684b4685c7)
- [Deploying a Iris Golang app in hasura](https://medium.com/@HasuraHQ/deploy-an-iris-golang-app-with-backend-apis-in-minutes-25a559bf530b)
- [How to Turn an Android Device into a Web Server](https://twitter.com/ThePracticalDev/status/892022594031017988)
- [A URL Shortener Service using Go, Iris and Bolt](https://medium.com/@kataras/a-url-shortener-service-using-go-iris-and-bolt-4182f0b00ae7)
- [Why I preferred Go over Node.js for simple Web Application](https://medium.com/@tigranbs/why-i-preferred-go-over-node-js-for-simple-web-application-d4a549e979b9)
I did some deep research and benchmarks with 'wrk' and 'ab' in order to choose which framework would suit me and my new project. The results, sadly, were really disappointing to me.
I started wondering if golang wasn't as fast on the web as I had read... but, before I let Golang go and continued to develop with nodejs, I told myself:
> '**Makis, don't lose hope, give at least a chance to Golang. Try to build something totally new without basing it off the "slow" code you saw earlier; learn the secrets of this language and make *others* follow your steps!**'.
These are the words I told myself that day [**13 March 2016**].
The same day, later the night, I was reading a book about Greek mythology. I saw an ancient goddess' name and was inspired immediately to give a name to this new web framework (which I had already started writing) - **Iris**.
I'm still here [because Iris has succeed in being the fastest go web framework](https://raw.githubusercontent.com/smallnest/go-web-framework-benchmark/4db507a22c964c9bc9774c5b31afdc199a0fe8b7/benchmark.png)
[![](http://comments.iris-go.com/screens/comment37.png)](https://twitter.com/ThePracticalDev/status/892022594031017988)
![](https://comments.iris-go.com/comment36.png)
![](https://comments.iris-go.com/comment35.png)
![](https://comments.iris-go.com/comment34.png)
![](https://comments.iris-go.com/comment2.png)
![](https://comments.iris-go.com/comment30.png)
![](https://comments.iris-go.com/comment31.png)
![](https://comments.iris-go.com/comment32.png)
![](https://comments.iris-go.com/comment33.png)
![](https://comments.iris-go.com/comment26.png)
![](https://comments.iris-go.com/comment1.png)
![](https://comments.iris-go.com/comment3.png)
![](https://comments.iris-go.com/comment8.png)
![](https://comments.iris-go.com/comment12.png)
![](https://comments.iris-go.com/comment13.png)
![](https://comments.iris-go.com/comment14.png)
![](https://comments.iris-go.com/comment17.png)
![](https://comments.iris-go.com/comment21.png)
![](https://comments.iris-go.com/comment22.png)
![](https://comments.iris-go.com/comment24.png)
![](https://comments.iris-go.com/comment27.png)
----
_iris_ is easy, it has a familiar API while in the same has far more features than [Gin](https://github.com/gin-gonic/gin) or [Martini](https://github.com/go-martini/martini).
You own your code —it will never generate (unfamiliar) code for you, like [Beego](https://github.com/astaxie/beego), [Revel](https://github.com/revel/revel) and [Buffalo](https://github.com/gobuffalo/buffalo) do.
It's not just-another-router but its overall performance is equivalent with something like [httprouter](https://github.com/julienschmidt/httprouter).
Unlike [fasthttp](https://github.com/valyala/fasthttp), iris provides full HTTP/2 support for free.
Compared to the rest open source projects, this one is very active and you get answers almost immediately.
### 🔥 Hot Features
- Focus on high performance
- Easy Fluent API
- Highly customizable
- Robust routing and middleware ecosystem
* Build RESTful APIs with iris unique expressionist path interpreter
* Dynamic path parameterized or wildcard routes are not conflict with static routes
* Remove trailing slash from the URL with option to redirect
* Virtual hosts and subdomains made easy
* Group API's and static or even dynamic subdomains
* MVC [**NEW**](_examples/mvc)
* `net/http` and `negroni-like` handlers are compatible via `iris.FromStd`
* Register custom handlers for any HTTP error
* Transactions and rollback when you need it
* Cache the response when you need it
* A single function to serve your embedded assets, always compatible with `go-bindata`
* HTTP to HTTPS
* HTTP to HTTPS WWW
* [learn the reasons that differ from what you've seen so far](_examples/#routing-grouping-dynamic-path-parameters-macros-and-custom-context)
- Context
* Highly scalable rich content render (Markdown, JSON, JSONP, XML...)
* Body binders and handy functions to send HTTP responses
* Limit request body
* Serve static resources or embedded assets
* Localization i18N
* Compression (Gzip is built'n)
- Authentication
* Basic Authentication
* OAuth, OAuth2 supporting 27+ popular websites
* JWT
- Server
* Automatically install and serve certificates from https://letsencrypt.org when serving via TLS
* Gracefully shutdown by-default
* Register on shutdown, error or interrupt events
* Attach more than one server, fully compatible with `net/http#Server`
- View system: supporting 5 template engines. Fully compatible with `html/template`
- HTTP Sessions library [you can still use your favorite if you want to]
- Websocket library, its API similar to socket.io [you can still use your favorite if you want to]
- Hot Reload on source code changes[*](https://github.com/kataras/rizla)
- Typescript integration + Web IDE
- And many other things that will surprise you
</details>
### 📖 Learn
<a href="https://github.com/kataras/iris/_examples" alt="documentation and examples">
<img align="right" src="learn.jpg" width="125" />
</a>
The _iris_ philosophy is to provide robust tooling for HTTP, making it a great solution for single page applications, web sites, hybrids, or public HTTP APIs. Keep note that, today, iris is faster than apache+nginx itself.
_iris_ does not force you to use any specific ORM. With support for the most popular template engines, websocket server and a fast sessions manager you can quickly craft your perfect application.
The awesome _iris_ community is always adding new examples, [_examples](_examples/) is a great place to get started!
Read the [godocs](https://godoc.org/github.com/kataras/iris) for a better understanding.
### 👥 Community
Join the welcoming community of fellow _iris_ developers in [rocket.chat](https://kataras.rocket.chat/channel/iris)
- [Post](http://support.iris-go.com) a feature request or report a bug
- :star: and watch the public [repository](https://github.com/kataras/iris/stargazers), will keep you up to date
- :earth_americas: publish [an article](https://medium.com/search?q=iris) or share a [tweet](https://twitter.com/hashtag/golang) about your personal experience with iris.
The most useful community repository for _iris_ developers is the
[iris-contrib/middleware](https://github.com/iris-contrib/middleware) which contains some HTTP handlers that can help you finish a lot of your tasks even easier. Feel free to push your own middleware there!
```sh
$ go get -u github.com/iris-contrib/middleware/...
```
#### 📈 One and a half years...
[![total used by](https://iris-go.com/graph?style=flat-square)]()
Iris exceeded all expectations, started as one-man project.
- 7300 github stars
- 778 github forks
- 1m total views at its documentation
- ~819$ at donations, small amount for the work we put here but it's a good start
- ~557 reported bugs fixed
- ~30 community feature requests have been implemented
### 📌 Version
Current: [VERSION](VERSION)
Each new release is pushed to the master. It stays there until the next version. When a next version is released then the previous version goes to its own branch with `gopkg.in` as its import path (and its own vendor folder), in order to keep it working "for-ever".
Changelog of the current version can be found at the [HISTORY](HISTORY.md) file.
#### Should I upgrade my iris?
Developers are not forced to use the latest _iris_ version, they can use any version in production, they can update at any time they want.
Testers should upgrade immediately, if you're willing to use _iris_ in production you can wait a little more longer, transaction should be as safe as possible.
#### Where can I find older versions?
Previous versions can be found at [releases page](https://github.com/kataras/iris/releases).
<!--
### 😃 Get Hired
Below you'll find a list of open positions that require at least **experience with the Iris web framework**.
| Company | Position | Job Details |
| -----------|--------|-------------|
| Kudo, an Indonesian startup technology company | Application Programming Interface Developer | Navigate to: https://glints.id/opportunities/jobs/5553 |
Employers that are looking for brilliant Software Engineers with good experience on Go Programming Language and Iris can put their startup's or company's name here or, if privacy is the key, [contact with us](mailto:kataras2006@hotmail.com?subject=Employer%20That%20Hires%20Smart%20Devs) to suggest some good and well-tested freelancers that suits your needs.
-->
### 🥇 People
The original author of _Iris_ is [@kataras](https://github.com/kataras), you can reach him via
- [Medium](https://medium.com/@kataras)
- [Twitter](https://twitter.com/makismaropoulos)
- [Dev.to](https://dev.to/@kataras)
- [Facebook](https://facebook.com/kataras.gopher)
- [Mail](mailto:kataras2006@hotmail.com?subject=Iris%20I%20need%20some%20help%20please)
[List of all Authors](AUTHORS)
[List of all Contributors](https://github.com/kataras/iris/graphs/contributors)
Help this project to continue deliver awesome and unique features with the higher code quality as possible by donating any amount via [PayPal](https://www.paypal.me/kataras)!
[![](https://www.paypalobjects.com/webstatic/paypalme/images/pp_logo_small.png)](https://www.paypal.me/kataras/20)
Take some time, `don't say we didn't warn you`, and continue your journey by [navigating to the bigger README page](README_BIG.md).
## License
This software is licensed under the open-source 3-Clause BSD.
You can find the license file [here](LICENSE), for any questions regarding the license please [contact](mailto:kataras2006@hotmail.com?subject=Iris%20License) us.
Iris is licensed under the 3-Clause BSD [License](LICENSE). Iris is 100% open-source software.

495
README_BIG.md Normal file
View File

@ -0,0 +1,495 @@
<!-- # ![Logo created by @santoshanand](logo_white_35_24.png) Iris -->
## 03, October 2017 | Iris User Experience Report
Be part of the **first** Iris User Experience Report by submitting a simple form, it won't take more than **5 minutes**.
The form contains some questions that you may need to answer in order to learn more about you; learning more about you helps us to serve you with the best possible way!
https://docs.google.com/forms/d/e/1FAIpQLSdCxZXPANg_xHWil4kVAdhmh7EBBHQZ_4_xSZVDL-oCC_z5pA/viewform?usp=sf_link
<a href="https://docs.google.com/forms/d/e/1FAIpQLSdCxZXPANg_xHWil4kVAdhmh7EBBHQZ_4_xSZVDL-oCC_z5pA/viewform?usp=sf_link"><img src="https://iris-go.com/public/images/user_experience_report.png" alt="Iris User Experience Report - Header" width="400"></a>
<p align="center">
<img src="iris_the_new_machine.gif">
</p>
Iris is a fast, simple and efficient micro web framework for Go. It provides a beautifully expressive and easy to use foundation for your next website, API, or distributed app.
We have no doubt you will able to find other web frameworks written in Go
and even put up a real fight to learn and use them for quite some time but
make no mistake, sooner or later you will be using Iris, not because of the ergonomic, high-performant solution that it provides but its well-documented unique features, as these will transform you to a real rockstar geek.
No matter what you're trying to build, Iris covers
every type of application, from micro services to large monolithic web applications.
It's actually the best piece of software for back-end web developers
you can find online.
Iris may have reached version 8, but we're not stopping there. We have many feature ideas on our board that we're anxious to add and other innovative web development solutions that we're planning to build into Iris.
Iris was built on top of the the [net/http](https://golang.org/pkg/net/http/) package, we own many thanks to [Brad Fitzpatrick](https://github.com/bradfitz) for that.
If you're coming from <a href="https://nodejs.org/en/">Node.js</a> world, this is the <a href="https://github.com/expressjs/express">expressjs</a> equivalent for the <a href="https://golang.org">Go Programming Language.</a><br/>
**Accelerated** by [KeyCDN](https://www.keycdn.com/), A Simple, Fast and Reliable CDN.
**We are developing** this project using the best code editor for Golang; [Visual Studio Code](https://code.visualstudio.com/) supported by [Microsoft](https://www.microsoft.com).
[Star](https://github.com/kataras/iris/stargazers) and watch this github repository to stay up to date.
<!-- [![total used by](https://iris-go.com/graph?style=flat-square)](https://iris-go.com/graph) -->
[![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)
[![github issues](https://img.shields.io/github/issues/kataras/iris.svg?style=flat-square)](https://github.com/kataras/iris/issues?q=is%3Aopen+is%3Aissue)
[![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)
[![release](https://img.shields.io/github/release/kataras/iris.svg?style=flat-square)](https://github.com/kataras/iris/releases)
[![view examples](https://img.shields.io/badge/learn%20by-examples-0077b3.svg?style=flat-square)](https://github.com/kataras/iris/tree/master/_examples)
[![chat](https://img.shields.io/badge/community-%20chat-00BCD4.svg?style=flat-square)](https://kataras.rocket.chat/channel/iris)
<!-- has issues, the img.shields.io's API is problematic for this resource: [![issue stats](https://img.shields.io/issuestats/i/github/kataras/iris.svg?style=flat-square)](https://github.com/kataras/iris/issues?q=is%3Aissue+is%3Aclosed) -->
<!-- [![godocs](https://img.shields.io/badge/godocs-8.x.x-0366d6.svg?style=flat-square)](https://godoc.org/github.com/kataras/iris) -->
![Iris vs .NET Core(C#) vs Node.js (Express)](https://iris-go.com/images/benchmark-new-gray.png)
<details>
<summary>Benchmarks from third-party source over the rest web frameworks</summary>
![Comparison with other frameworks](https://raw.githubusercontent.com/smallnest/go-web-framework-benchmark/4db507a22c964c9bc9774c5b31afdc199a0fe8b7/benchmark.png)
</details>
_Updated at: [Friday, 29 September 2017](_benchmarks)_
</p>
### [🎗️](#-people) Legends
Help this project to continue deliver awesome and unique features with the higher code quality as possible by donating any amount via [PayPal](https://www.paypal.me/kataras)!
| Name | Amount | Membership |
| -----------|--------|--------|
| [Juan Sebastián Suárez Valencia](https://github.com/Juanses) | 20 EUR | Bronze |
| [Bob Lee](https://github.com/li3p) | 20 EUR | Bronze |
| [Celso Luiz](https://github.com/celsosz) | 50 EUR | **Silver** |
| [Ankur Srivastava](https://github.com/ansrivas) | 20 EUR | Bronze |
| [Damon Zhao](https://github.com/se77en) | 20 EUR | Bronze |
| [Exponity - Tech Company](https://github.com/exponity) | 30 EUR | Bronze |
| [Thomas Fritz](https://github.com/thomasfr) | 25 EUR | Bronze |
| [Thanos V.](http://mykonosbiennale.com/) | 20 EUR | Bronze |
| [George Opritescu](https://github.com/International) | 20 EUR | Bronze |
| [Lex Tang](https://github.com/lexrus) | 20 EUR | Bronze |
| [Bill Q.](https://github.com/hiveminded) | 600 EUR | **Gold** |
| [Conrad Steenberg](https://github.com/hengestone) | 25 EUR | Bronze |
_Psst_, we've produced a small video about your feelings regrating to Iris! You can watch the video at https://www.youtube.com/watch?v=jGx0LkuUs4A.
### 📑 Table Of Content
* [Installation](#-installation)
* [Latest changes](https://github.com/kataras/iris/blob/master/HISTORY.md#fr-06-october-2017--v845)
* [Learn](#-learn)
* [Structuring](_examples/#structuring)
* [HTTP Listening](_examples/#http-listening)
* [Configuration](_examples/#configuration)
* [Routing, Grouping, Dynamic Path Parameters, "Macros" and Custom Context](_examples/#routing-grouping-dynamic-path-parameters-macros-and-custom-context)
* [MVC (Model View Controller)](_examples/#mvc) **NEW**
* [Subdomains](_examples/#subdomains)
* [Wrap `http.Handler/HandlerFunc`](_examples/#convert-httphandlerhandlerfunc)
* [View](_examples/#view)
* [Authentication](_examples/#authentication)
* [File Server](_examples/#file-server)
* [How to Read from `context.Request() *http.Request`](_examples/#how-to-read-from-contextrequest-httprequest)
* [How to Write to `context.ResponseWriter() http.ResponseWriter`](_examples/#how-to-write-to-contextresponsewriter-httpresponsewriter)
* [Test](_examples/#testing)
* [Cache](_examples/#caching)
* [Sessions](_examples/#sessions)
* [Websockets](_examples/#websockets)
* [Miscellaneous](_examples/#miscellaneous)
* [POC: Convert the medium-sized project "Parrot" from native to Iris](https://github.com/iris-contrib/parrot)
* [POC: Isomorphic react/hot reloadable/redux/css-modules starter kit](https://github.com/kataras/iris-starter-kit)
* [Typescript Automation Tools](typescript/#table-of-contents)
* [Tutorial: Online Visitors](_examples/tutorial/online-visitors)
* [Tutorial: Caddy](_examples/tutorial/caddy)
* [Tutorial: DropzoneJS Uploader](_examples/tutorial/dropzonejs)
* [Middleware](middleware/)
* [Dockerize](https://github.com/iris-contrib/cloud-native-go)
* [Community & Support](#-community)
* [Blogs](https://iris-go.com/v8/blogs)
- [How to build a file upload form using DropzoneJS and Go](https://hackernoon.com/how-to-build-a-file-upload-form-using-dropzonejs-and-go-8fb9f258a991)
- [How to display existing files on server using DropzoneJS and Go](https://hackernoon.com/how-to-display-existing-files-on-server-using-dropzonejs-and-go-53e24b57ba19)
- [Iris Go vs .NET Core Kestrel in terms of HTTP performance](https://hackernoon.com/iris-go-vs-net-core-kestrel-in-terms-of-http-performance-806195dc93d5)
- [Go vs .NET Core in terms of HTTP performance](https://medium.com/@kataras/go-vs-net-core-in-terms-of-http-performance-7535a61b67b8)
- [Iris, a modular web framework](https://medium.com/@corebreaker/iris-web-cd684b4685c7)
- [Deploying a Iris Golang app in hasura](https://medium.com/@HasuraHQ/deploy-an-iris-golang-app-with-backend-apis-in-minutes-25a559bf530b)
- [How to Turn an Android Device into a Web Server](https://twitter.com/ThePracticalDev/status/892022594031017988)
- [A URL Shortener Service using Go, Iris and Bolt](https://medium.com/@kataras/a-url-shortener-service-using-go-iris-and-bolt-4182f0b00ae7)
- [Why I preferred Go over Node.js for simple Web Application](https://medium.com/@tigranbs/why-i-preferred-go-over-node-js-for-simple-web-application-d4a549e979b9)
* [Versioning](#-version)
* [People](#-people)
### 🚀 Installation
The only requirement is the [Go Programming Language](https://golang.org/dl/), at least version 1.8, but **1.9** is highly recommended. [Docs](https://docs.iris-go.com) and [Examples](_examples) are written using the go 1.9 version.
```sh
$ go get -u github.com/kataras/iris
```
> _iris_ takes advantage of the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature. You get truly reproducible builds, as this method guards against upstream renames and deletes.
```go
// file: main.go
package main
import "github.com/kataras/iris"
func main() {
app := iris.New()
// Load all templates from the "./views" folder
// where extension is ".html" and parse them
// using the standard `html/template` package.
app.RegisterView(iris.HTML("./views", ".html"))
// Method: GET
// Resource: http://localhost:8080
app.Get("/", func(ctx iris.Context) {
// Bind: {{.message}} with "Hello world!"
ctx.ViewData("message", "Hello world!")
// Render template file: ./views/hello.html
ctx.View("hello.html")
})
// Method: GET
// Resource: http://localhost:8080/user/42
//
// Need to use a custom regexp instead?
// Easy;
// Just mark the parameter's type to 'string'
// which accepts anything and make use of
// its `regexp` macro function, i.e:
// app.Get("/user/{id:string regexp(^[0-9]+$)}")
app.Get("/user/{id:long}", func(ctx iris.Context) {
userID, _ := ctx.Params().GetInt64("id")
ctx.Writef("User ID: %d", userID)
})
// Start the server using a network address.
app.Run(iris.Addr(":8080"))
}
```
> See all available path parameter types at: https://github.com/kataras/iris/blob/master/_examples/routing/dynamic-path/main.go#L31
```html
<!-- file: ./views/hello.html -->
<html>
<head>
<title>Hello Page</title>
</head>
<body>
<h1>{{.message}}</h1>
</body>
</html>
```
```sh
$ go run main.go
> Now listening on: http://localhost:8080
> Application started. Press CTRL+C to shut down.
```
> Examples and docs are updated to Go 1.9, please refer to that [section](https://github.com/kataras/iris/blob/master/faq.md#type-aliases) before anything else.
<details>
<summary>Hello World with Go 1.8</summary>
Iris declares all of its type alias at the same file in order to be easy to be discovered.
> If you just upgraded to go 1.9 from 1.8 you can always search for a compatible type alias at the [context.go](context.go) file and opposite, if you use go 1.8 and you're new to Iris you can see [that](context.go) file to see the compatible packages.
If Go 1.8 remains the basic host for your go apps then you should declare and use the `github.com/kataras/iris/context` package on your source file's imports statement.
```go
package main
import (
"github.com/kataras/iris"
"github.com/kataras/iris/context"
)
func main() {
app := iris.New()
app.RegisterView(iris.HTML("./templates", ".html"))
app.Get("/", func(ctx context.Context) {
ctx.ViewData("message", "Hello world!")
ctx.View("hello.html")
})
app.Run(iris.Addr(":8080"))
}
```
</details>
<details>
<summary>Fan of the MVC Architectural Pattern? Click here</summary>
```go
package main
import "github.com/kataras/iris"
func main() {
app := iris.New()
app.RegisterView(iris.HTML("./views", ".html"))
app.Controller("/", new(Controller))
app.Run(iris.Addr(":8080"))
}
type Controller struct {
iris.Controller
}
// Method: GET
// Resource: http://localhost:8080
func (c *Controller) Get() {
c.Data["message"] = "Hello world!"
c.Tmpl = "hello.html"
}
// Method: GET
// Resource: http://localhost:8080/user/42
func (c *Controller) GetUserBy(id int64) {
c.Ctx.Writef("User ID: %d", id)
}
```
</details>
<details>
<summary>Why a new web framework</summary>
### Why
Go is a great technology stack for building scalable, web-based, back-end systems for web
applications.
When you think about building web applications and web APIs, or simply building HTTP servers in Go, does your mind go to the standard net/http package?
Then you have to deal with some common situations like dynamic routing (a.k.a parameterized), security and authentication, real-time communication and many other issues that net/http doesn't solve.
The net/http package is not complete enough to quickly build well-designed back-end web systems. When you realize this, you might be thinking along these lines:
- Ok, the net/http package doesn't suit me, but there are so many frameworks, which one will work for me?!
- Each one of them tells me that it is the best. I don't know what to do!
##### The truth
I did some deep research and benchmarks with 'wrk' and 'ab' in order to choose which framework would suit me and my new project. The results, sadly, were really disappointing to me.
I started wondering if golang wasn't as fast on the web as I had read... but, before I let Golang go and continued to develop with nodejs, I told myself:
> '**Makis, don't lose hope, give at least a chance to Golang. Try to build something totally new without basing it off the "slow" code you saw earlier; learn the secrets of this language and make *others* follow your steps!**'.
These are the words I told myself that day [**13 March 2016**].
The same day, later the night, I was reading a book about Greek mythology. I saw an ancient goddess' name and was inspired immediately to give a name to this new web framework (which I had already started writing) - **Iris**.
I'm still here [because Iris has succeed in being the fastest go web framework](https://raw.githubusercontent.com/smallnest/go-web-framework-benchmark/4db507a22c964c9bc9774c5b31afdc199a0fe8b7/benchmark.png)
[![](http://comments.iris-go.com/screens/comment37.png)](https://twitter.com/ThePracticalDev/status/892022594031017988)
![](https://comments.iris-go.com/comment36.png)
![](https://comments.iris-go.com/comment35.png)
![](https://comments.iris-go.com/comment34.png)
![](https://comments.iris-go.com/comment2.png)
![](https://comments.iris-go.com/comment30.png)
![](https://comments.iris-go.com/comment31.png)
![](https://comments.iris-go.com/comment32.png)
![](https://comments.iris-go.com/comment33.png)
![](https://comments.iris-go.com/comment26.png)
![](https://comments.iris-go.com/comment1.png)
![](https://comments.iris-go.com/comment3.png)
![](https://comments.iris-go.com/comment8.png)
![](https://comments.iris-go.com/comment12.png)
![](https://comments.iris-go.com/comment13.png)
![](https://comments.iris-go.com/comment14.png)
![](https://comments.iris-go.com/comment17.png)
![](https://comments.iris-go.com/comment21.png)
![](https://comments.iris-go.com/comment22.png)
![](https://comments.iris-go.com/comment24.png)
![](https://comments.iris-go.com/comment27.png)
----
_iris_ is easy, it has a familiar API while in the same has far more features than [Gin](https://github.com/gin-gonic/gin) or [Martini](https://github.com/go-martini/martini).
You own your code —it will never generate (unfamiliar) code for you, like [Beego](https://github.com/astaxie/beego), [Revel](https://github.com/revel/revel) and [Buffalo](https://github.com/gobuffalo/buffalo) do.
It's not just-another-router but its overall performance is equivalent with something like [httprouter](https://github.com/julienschmidt/httprouter).
Unlike [fasthttp](https://github.com/valyala/fasthttp), iris provides full HTTP/2 support for free.
Compared to the rest open source projects, this one is very active and you get answers almost immediately.
### 🔥 Hot Features
- Focus on high performance
- Easy Fluent API
- Highly customizable
- Robust routing and middleware ecosystem
* Build RESTful APIs with iris unique expressionist path interpreter
* Dynamic path parameterized or wildcard routes are not conflict with static routes
* Remove trailing slash from the URL with option to redirect
* Virtual hosts and subdomains made easy
* Group API's and static or even dynamic subdomains
* MVC [**NEW**](_examples/mvc)
* `net/http` and `negroni-like` handlers are compatible via `iris.FromStd`
* Register custom handlers for any HTTP error
* Transactions and rollback when you need it
* Cache the response when you need it
* A single function to serve your embedded assets, always compatible with `go-bindata`
* HTTP to HTTPS
* HTTP to HTTPS WWW
* [learn the reasons that differ from what you've seen so far](_examples/#routing-grouping-dynamic-path-parameters-macros-and-custom-context)
- Context
* Highly scalable rich content render (Markdown, JSON, JSONP, XML...)
* Body binders and handy functions to send HTTP responses
* Limit request body
* Serve static resources or embedded assets
* Localization i18N
* Compression (Gzip is built'n)
- Authentication
* Basic Authentication
* OAuth, OAuth2 supporting 27+ popular websites
* JWT
- Server
* Automatically install and serve certificates from https://letsencrypt.org when serving via TLS
* Gracefully shutdown by-default
* Register on shutdown, error or interrupt events
* Attach more than one server, fully compatible with `net/http#Server`
- View system: supporting 5 template engines. Fully compatible with `html/template`
- HTTP Sessions library [you can still use your favorite if you want to]
- Websocket library, its API similar to socket.io [you can still use your favorite if you want to]
- Hot Reload on source code changes[*](https://github.com/kataras/rizla)
- Typescript integration + Web IDE
- And many other things that will surprise you
</details>
### 📖 Learn
<a href="https://github.com/kataras/iris/_examples" alt="documentation and examples">
<img align="right" src="learn.jpg" width="125" />
</a>
The _iris_ philosophy is to provide robust tooling for HTTP, making it a great solution for single page applications, web sites, hybrids, or public HTTP APIs. Keep note that, today, iris is faster than apache+nginx itself.
_iris_ does not force you to use any specific ORM. With support for the most popular template engines, websocket server and a fast sessions manager you can quickly craft your perfect application.
The awesome _iris_ community is always adding new examples, [_examples](_examples/) is a great place to get started!
Read the [godocs](https://godoc.org/github.com/kataras/iris) for a better understanding.
### 👥 Community
Join the welcoming community of fellow _iris_ developers in [rocket.chat](https://kataras.rocket.chat/channel/iris)
- [Post](http://support.iris-go.com) a feature request or report a bug
- :star: and watch the public [repository](https://github.com/kataras/iris/stargazers), will keep you up to date
- :earth_americas: publish [an article](https://medium.com/search?q=iris) or share a [tweet](https://twitter.com/hashtag/golang) about your personal experience with iris.
The most useful community repository for _iris_ developers is the
[iris-contrib/middleware](https://github.com/iris-contrib/middleware) which contains some HTTP handlers that can help you finish a lot of your tasks even easier. Feel free to push your own middleware there!
```sh
$ go get -u github.com/iris-contrib/middleware/...
```
#### 📈 One and a half years...
[![total used by](https://iris-go.com/graph?style=flat-square)]()
Iris exceeded all expectations, started as one-man project.
- 7300 github stars
- 778 github forks
- 1m total views at its documentation
- ~819$ at donations, small amount for the work we put here but it's a good start
- ~557 reported bugs fixed
- ~30 community feature requests have been implemented
### 📌 Version
Current: [VERSION](VERSION)
Each new release is pushed to the master. It stays there until the next version. When a next version is released then the previous version goes to its own branch with `gopkg.in` as its import path (and its own vendor folder), in order to keep it working "for-ever".
Changelog of the current version can be found at the [HISTORY](HISTORY.md) file.
#### Should I upgrade my iris?
Developers are not forced to use the latest _iris_ version, they can use any version in production, they can update at any time they want.
Testers should upgrade immediately, if you're willing to use _iris_ in production you can wait a little more longer, transaction should be as safe as possible.
#### Where can I find older versions?
Previous versions can be found at [releases page](https://github.com/kataras/iris/releases).
<!--
### 😃 Get Hired
Below you'll find a list of open positions that require at least **experience with the Iris web framework**.
| Company | Position | Job Details |
| -----------|--------|-------------|
| Kudo, an Indonesian startup technology company | Application Programming Interface Developer | Navigate to: https://glints.id/opportunities/jobs/5553 |
Employers that are looking for brilliant Software Engineers with good experience on Go Programming Language and Iris can put their startup's or company's name here or, if privacy is the key, [contact with us](mailto:kataras2006@hotmail.com?subject=Employer%20That%20Hires%20Smart%20Devs) to suggest some good and well-tested freelancers that suits your needs.
-->
### 🥇 People
The original author of _Iris_ is [@kataras](https://github.com/kataras), you can reach him via
- [Medium](https://medium.com/@kataras)
- [Twitter](https://twitter.com/makismaropoulos)
- [Dev.to](https://dev.to/@kataras)
- [Facebook](https://facebook.com/kataras.gopher)
- [Mail](mailto:kataras2006@hotmail.com?subject=Iris%20I%20need%20some%20help%20please)
[List of all Authors](AUTHORS)
[List of all Contributors](https://github.com/kataras/iris/graphs/contributors)
Help this project to continue deliver awesome and unique features with the higher code quality as possible by donating any amount via [PayPal](https://www.paypal.me/kataras)!
[![](https://www.paypalobjects.com/webstatic/paypalme/images/pp_logo_small.png)](https://www.paypal.me/kataras/20)
## License
This software is licensed under the open-source 3-Clause BSD.
You can find the license file [here](LICENSE), for any questions regarding the license please [contact](mailto:kataras2006@hotmail.com?subject=Iris%20License) us.

View File

@ -1 +1 @@
8.4.4:https://github.com/kataras/iris/blob/master/HISTORY.md#su-01-october-2017--v844
8.4.5:https://github.com/kataras/iris/blob/master/HISTORY.md#fr-06-october-2017--v845

View File

@ -48,7 +48,6 @@ func main() {
// this should be added to the logs, at the end because of the `logger.Config#MessageContextKey`
ctx.Values().Set("logger_message",
"a dynamic message passed to the logs")
ctx.Writef("My Custom error page")
})

View File

@ -2,6 +2,14 @@ package main
import (
"github.com/kataras/iris"
"github.com/kataras/iris/mvc"
// auto-completion does not working well with type aliases
// when embedded fields.
// We should complete a report on golang repo for that at some point.
//
// Therefore import the "mvc" package manually
// here at "hello-world" so users can see that
// import path somewhere else than the "FAQ" section.
"github.com/kataras/iris/middleware/logger"
"github.com/kataras/iris/middleware/recover"
@ -45,8 +53,10 @@ func main() {
// ExampleController serves the "/", "/ping" and "/hello".
type ExampleController struct {
// if you build with go1.8 you have to use the mvc package, `mvc.Controller` instead.
iris.Controller
// if you build with go1.8 you have to use the mvc package always,
// otherwise
// you can simply use `iris.Controller`.
mvc.Controller
}
// Get serves

View File

@ -18,7 +18,7 @@ func (u *VisitController) Get() {
// get the visits, before calcuate this new one.
visits, _ := u.Session.GetIntDefault("visits", 0)
// increment the visits counter and set them to the session.
// increment the visits and store to the session.
visits++
u.Session.Set("visits", visits)

2
doc.go
View File

@ -35,7 +35,7 @@ Source code and other details for the project are available at GitHub:
Current Version
8.4.4
8.4.5
Installation

View File

@ -32,7 +32,7 @@ import (
const (
// Version is the current version number of the Iris Web Framework.
Version = "8.4.4"
Version = "8.4.5"
)
// HTTP status codes as registered with IANA.

View File

@ -67,7 +67,6 @@ func (p *funcParser) parse() (*ast, error) {
}
if w == tokenBy {
typ := p.info.Type
funcArgPos++ // starting with 1 because in typ.NumIn() the first is the struct receiver.
// No need for these:
@ -79,39 +78,10 @@ func (p *funcParser) parse() (*ast, error) {
// continue
// }
if typ.NumIn() <= funcArgPos {
// old:
// return nil, errors.New("keyword 'By' found but length of input receivers are not match for " +
// p.info.Name)
// By found but input arguments are not there, so act like /by path without restricts.
a.relPath += "/" + strings.ToLower(w)
continue
if err := p.parsePathParam(a, w, funcArgPos); err != nil {
return nil, err
}
var (
paramKey = genParamKey(funcArgPos) // paramfirst, paramsecond...
paramType = paramTypeString // default string
)
// string, int...
goType := typ.In(funcArgPos).Name()
if p.lexer.peekNext() == tokenWildcard {
p.lexer.skip() // skip the Wildcard word.
paramType = paramTypePath
} else if pType, ok := macroTypes[goType]; ok {
// it's not wildcard, so check base on our available macro types.
paramType = pType
} else {
return nil, errors.New("invalid syntax for " + p.info.Name)
}
a.paramKeys = append(a.paramKeys, paramKey)
a.paramTypes = append(a.paramTypes, paramType)
// /{paramfirst:path}, /{paramfirst:long}...
a.relPath += fmt.Sprintf("/{%s:%s}", paramKey, paramType)
a.dynamic = true
continue
}
@ -120,6 +90,57 @@ func (p *funcParser) parse() (*ast, error) {
return a, nil
}
func (p *funcParser) parsePathParam(a *ast, w string, funcArgPos int) error {
typ := p.info.Type
if typ.NumIn() <= funcArgPos {
// old:
// return nil, errors.New("keyword 'By' found but length of input receivers are not match for " +
// p.info.Name)
// By found but input arguments are not there, so act like /by path without restricts.
a.relPath += "/" + strings.ToLower(w)
return nil
}
var (
paramKey = genParamKey(funcArgPos) // paramfirst, paramsecond...
paramType = paramTypeString // default string
)
// string, int...
goType := typ.In(funcArgPos).Name()
nextWord := p.lexer.peekNext()
if nextWord == tokenWildcard {
p.lexer.skip() // skip the Wildcard word.
paramType = paramTypePath
} else if pType, ok := macroTypes[goType]; ok {
// it's not wildcard, so check base on our available macro types.
paramType = pType
} else {
return errors.New("invalid syntax for " + p.info.Name)
}
a.paramKeys = append(a.paramKeys, paramKey)
a.paramTypes = append(a.paramTypes, paramType)
// /{paramfirst:path}, /{paramfirst:long}...
a.relPath += fmt.Sprintf("/{%s:%s}", paramKey, paramType)
a.dynamic = true
if nextWord == "" && typ.NumIn() > funcArgPos+1 {
// By is the latest word but func is expected
// more path parameters values, i.e:
// GetBy(name string, age int)
// The caller (parse) doesn't need to know
// about the incremental funcArgPos because
// it will not need it.
return p.parsePathParam(a, nextWord, funcArgPos+1)
}
return nil
}
type ast struct {
paramKeys []string // paramfirst, paramsecond... [0]
paramTypes []string // string, int, long, path... [0]

View File

@ -221,6 +221,12 @@ func (c *Controller) Write(contents []byte) (int, error) {
return c.Ctx.ResponseWriter().Write(contents)
}
// Writef formats according to a format specifier and writes to the response.
func (c *Controller) Writef(format string, a ...interface{}) (int, error) {
c.tryWriteHeaders()
return c.Ctx.ResponseWriter().Writef(format, a...)
}
// BeginRequest starts the main controller
// it initialize the Ctx and other fields.
//

View File

@ -446,18 +446,20 @@ func (c *testControllerRelPathFromFunc) EndRequest(ctx context.Context) {
c.Controller.EndRequest(ctx)
}
func (c *testControllerRelPathFromFunc) Get() {}
func (c *testControllerRelPathFromFunc) GetBy(int64) {}
func (c *testControllerRelPathFromFunc) GetByWildcard(string) {}
func (c *testControllerRelPathFromFunc) Get() {}
func (c *testControllerRelPathFromFunc) GetBy(int64) {}
func (c *testControllerRelPathFromFunc) GetAnythingByWildcard(string) {}
func (c *testControllerRelPathFromFunc) GetLogin() {}
func (c *testControllerRelPathFromFunc) PostLogin() {}
func (c *testControllerRelPathFromFunc) GetAdminLogin() {}
func (c *testControllerRelPathFromFunc) PutSomethingIntoThis() {}
func (c *testControllerRelPathFromFunc) PutSomethingIntoThis() {}
func (c *testControllerRelPathFromFunc) GetSomethingBy(bool) {}
func (c *testControllerRelPathFromFunc) GetSomethingByBy(string, int) {}
func (c *testControllerRelPathFromFunc) GetSomethingNewBy(string, int) {} // two input arguments, one By which is the latest word.
func (c *testControllerRelPathFromFunc) GetSomethingByElseThisBy(bool, int) {} // two input arguments
func TestControllerRelPathFromFunc(t *testing.T) {
@ -478,6 +480,8 @@ func TestControllerRelPathFromFunc(t *testing.T) {
e.GET("/something/falsee").Expect().Status(httptest.StatusNotFound)
e.GET("/something/kataras/42").Expect().Status(httptest.StatusOK).
Body().Equal("GET:/something/kataras/42")
e.GET("/something/new/kataras/42").Expect().Status(httptest.StatusOK).
Body().Equal("GET:/something/new/kataras/42")
e.GET("/something/true/else/this/42").Expect().Status(httptest.StatusOK).
Body().Equal("GET:/something/true/else/this/42")