Iris is an efficient and well-designed toolbox with robust set of features.
Write your own
perfect high-performance web applications
with unlimited potentials and portability.
If you're coming from Node.js world, this is the expressjs equivalent for the Go Programming Language.
- Godocs ⇒ https://godoc.org/gopkg.in/kataras/iris.v6
- Getting Started with Go+Iris ⇒ http://gopherbook.iris-go.com
- Navigate through community examples ⇒ https://github.com/iris-contrib/examples
- [./adaptors](https://github.com/kataras/iris/tree/v6/adaptors) and [./middleware](https://github.com/kataras/iris/tree/v6/middleware) contains examples of their usage.
- [HISTORY.md](https://github.com//kataras/iris/tree/v6/HISTORY.md) is your best friend, version migrations are released there.
Overview
-----------
```go
package main
import (
"gopkg.in/kataras/iris.v6"
"gopkg.in/kataras/iris.v6/adaptors/cors"
"gopkg.in/kataras/iris.v6/adaptors/httprouter"
"gopkg.in/kataras/iris.v6/adaptors/view"
)
func main() {
// Receives optional iris.Configuration{}, see ./configuration.go
// for more.
app := iris.New()
// Order doesn't matter,
// You can split it to different .Adapt calls.
// See ./adaptors folder for more.
app.Adapt(
// adapt a logger which prints all errors to the os.Stdout
iris.DevLogger(),
// adapt the adaptors/httprouter or adaptors/gorillamux
httprouter.New(),
// 5 template engines are supported out-of-the-box:
//
// - standard html/template
// - amber
// - django
// - handlebars
// - pug(jade)
//
// Use the html standard engine for all files inside "./views" folder with extension ".html"
view.HTML("./views", ".html"),
// Cors wrapper to the entire application, allow all origins.
cors.New(cors.Options{AllowedOrigins: []string{"*"}}))
// http://localhost:6300
// Method: "GET"
// Render ./views/index.html
app.Get("/", func(ctx *iris.Context) {
ctx.Render("index.html", iris.Map{"Title": "Page Title"}, iris.RenderOptions{"gzip": true})
})
// Group routes, optionally: share middleware, template layout and custom http errors.
userAPI := app.Party("/users", userAPIMiddleware).
Layout("layouts/userLayout.html")
{
// Fire userNotFoundHandler when Not Found
// inside http://localhost:6300/users/*anything
userAPI.OnError(404, userNotFoundHandler)
// http://localhost:6300/users
// Method: "GET"
userAPI.Get("/", getAllHandler)
// http://localhost:6300/users/42
// Method: "GET"
userAPI.Get("/:id", getByIDHandler)
// http://localhost:6300/users
// Method: "POST"
userAPI.Post("/", saveUserHandler)
}
// Start the server at 127.0.0.1:6300
app.Listen(":6300")
}
func userAPIMiddleware(ctx *iris.Context) {
// your code here...
println("Request: " + ctx.Path())
ctx.Next() // go to the next handler(s)
}
func userNotFoundHandler(ctx *iris.Context) {
// your code here...
ctx.HTML(iris.StatusNotFound, "
> Q: Why no `serverless`?
New web developers are so enthusiastic about the idea of `serverless` and `AWS`. Most of the experienced developers we already know that we shouldn't use these things for our critical parts of our application.
**`Serverless and AWS` Are Wonderful—Until They Go Wrong.** There was a flash-point (at 28 February of 2017) where the 'internet was offline' and most of the sites, including isitdownrightnow.com, were down or operated very slow! Why? Because of `serverless` and `AmazonS3`.
Please think twice before moving your code into `serverless`, **instead, use web frameworks that are created for servers that you control**, i.e Iris.
Proof of concept:
- [Washington Post](https://www.washingtonpost.com/news/the-switch/wp/2017/02/28/why-a-whole-slew-of-websites-are-suddenly-down-or-working-slowly)
- [CNN](http://money.cnn.com/2017/02/28/technology/amazon-web-services-outages/index.html)
- [CNET](https://www.cnet.com/news/no-the-internet-is-not-broken-amazon-web-services-is-just-having-issues/?ftag=COS-05-10-aa0a&linkId=34980800)
- [MIT Technology Review](https://www.technologyreview.com/s/603738/centralized-web-services-are-wonderful-until-they-go-wrong/?_ga=1.82562070.1263144274.1488319022)
- [GolangNews](https://golangnews.com/stories/1835-serverless-is-wonderfuluntil-they-go-wrong.)
Explore [these questions](http://support.iris-go.com/) and join to our [community chat][Chat]!
Testing
------------
The `httptest` package is a simple Iris helper for the httpexpect, a new library for End-to-end HTTP and REST API testing for Go.
You can find tests by navigating to the source code,
i.e:
- [context_test.go](https://github.com/kataras/iris/blob/v6/context_test.go)
- [handler_test.go](https://github.com/kataras/iris/blob/v6/handler_test.go)
- [policy_gorillamux_test.go](https://github.com/kataras/iris/blob/v6/policy_gorillamux_test.go)
- [policy_httprouter_test.go](https://github.com/kataras/iris/blob/v6/policy_httprouter_test.go)
- [policy_nativerouter_test.go](https://github.com/kataras/iris/blob/v6/policy_nativerouter_test.go)
- [policy_render_test.go](https://github.com/kataras/iris/blob/v6/policy_render_test.go)
- [policy_sessions_test.go](https://github.com/kataras/iris/blob/v6/policy_sessions_test.go)
- [response_writer_test.go](https://github.com/kataras/iris/blob/v6/response_writer_test.go)
- [route_test.go](https://github.com/kataras/iris/blob/v6/route_test.go)
- [status_test.go](https://github.com/kataras/iris/blob/v6/status_test.go)
- [transaction_test.go](https://github.com/kataras/iris/blob/v6/transaction_test.go)
A simple test is located to [./httptest/_example/main_test.go](https://github.com/kataras/iris/blob/v6/httptest/_example/main_test.go)
httpexpect's repository has some Iris examples too:
- https://github.com/gavv/httpexpect/blob/master/_examples/iris.go (without `httptest` package)
- https://github.com/gavv/httpexpect/blob/master/_examples/iris_test.go (without `httptest` package)
Read more about httpexpect [here](https://github.com/gavv/httpexpect).
Philosophy
------------
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 nginx itself.
Iris does not force you to use any specific ORM or template engine. Iris is routerless which means you can adapt any router you like, [httprouter](https://github.com/kataras/iris/blob/v6/adaptors/httprouter/_example/main.go) is the fastest, [gorillamux](https://github.com/kataras/iris/blob/v6/adaptors/gorillamux/_example/main.go) has more features. With support for the most used template engines (5), you can quickly craft the perfect application.
People
------------
The author of Iris is [@kataras](https://github.com/kataras).
However the real Success of Iris belongs to you with your bug reports and feature requests that made this Framework so Unique.
Support
------------
The main purpose of donations to open source is to say "thank you" to the developer rather than actually advancing the project.
Open source projects don’t need the money like those charities do—and so it’s usually phrased like: *Buy the developer a cup of coffee*.
### Buy me a cup of coffee?
Iris is free and open source but developing it has taken thousands of hours of my time and a large part of my sanity. If you feel this web framework useful to you, it would go a great way to ensuring that I can afford to take the time to continue to develop it.
Thanks for your gratitude and finance help ♡
[](https://www.paypal.me/kataras/25eur)
Some of the benefits are listed here:
- Your github username, after your approval, is visible at the top of the README page.
- Access to the 'donors' [private chat room](https://kataras.rocket.chat/group/donors) gives you real-time assistance by Iris' Author.
> *ANONYMOUS*: People who donate but don't want to be shown here.
*ANONYMOUS* are listed as one group instead of an individual entry, in order to protect their exact date of their donation.
> The names, shown at the [supporters](https://github.com/kataras/iris#heroes-) list, are sorted by **date** and **NOT by the amount** of the donation.
### More options!
- Star the project, will help you to follow the upcoming features.
- Write an article about Iris or even post a Tweet.
- If you are interested in contributing to the Iris project, please see the document [CONTRIBUTING](https://github.com/kataras/iris/blob/master/.github/CONTRIBUTING.md).
### Become An Iris Sponsor
Want to add your company's logo to our [website](http://iris-go.com)?
Please contact me via email: kataras2006@hotmail.com
Thank you!
Socialize
------------
Besides the fact that we have a [community chat][Chat] for questions or reports and ideas, [stackoverflow](http://stackoverflow.com/) section for generic go+iris questions and the [iris support](http://support.iris-go.com) for bug reports and feature requests, you can also contact with me, as a person who is always open to help you:
- [Twitter](https://twitter.com/MakisMaropoulos)
- [Facebook](https://facebook.com/kataras.gopher)
- [Linkedin](https://www.linkedin.com/in/gerasimos-maropoulos)
Versioning
------------
Current: **v6**, code-named as "√Νεxτ"
v5: https://github.com/kataras/iris/tree/5.0.0
License
------------
Unless otherwise noted, the source files are distributed
under the MIT License found in the [LICENSE file](LICENSE).
Note that some optional components that you may use with Iris requires
different license agreements.
TODO
------------
- [ ] Refactor the [Examples](https://github.com/iris-contrib/examples) to be align with the latest version
- [ ] Upgrade [GitBook](https://docs.iris-go.com) for the latest release
Iris is a Community-Driven project waiting for your [feature requests](http://support.iris-go.com/t/feature-request)!
[Chat]: https://kataras.rocket.chat/channel/iris