Former-commit-id: ed84f99c89f43fe5e980a8e6d0ee22c186f0e1b9
9.9 KiB
Iris provides efficient and well-designed toolbox with robust set of features to
create your own
perfect high-performance web application
with unlimited portability using the Go Programming Language.
Easy to learn while it's highly customizable,
ideally suited for
both experienced and novice developers.
If you're coming from Node.js world, this is the expressjs for the Go Programming Language.
Installation
The only requirement is the Go Programming Language, at least v1.7.
$ go get gopkg.in/kataras/iris.v6
Overview
package main
import (
"gopkg.in/kataras/iris.v6"
"gopkg.in/kataras/iris.v6/adaptors/httprouter"
"gopkg.in/kataras/iris.v6/adaptors/view"
)
func main() {
app := iris.New()
app.Adapt(iris.Devlogger()) // adapt a logger which prints all errors to the os.Stdout
app.Adapt(httprouter.New()) // adapt the adaptors/httprouter or adaptors/gorillamux
// 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"
templates := view.HTML("./views", ".html")
app.Adapt(templates)
// http://localhost:6200
// Method: "GET"
// Render ./views/index.html
app.Get("/", func(ctx *iris.Context) {
ctx.Render("index.html", nil)
})
// 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:6200/users/*anything
userAPI.OnError(404, userNotFoundHandler)
// http://localhost:6200/users
// Method: "GET"
userAPI.Get("/", getAllHandler)
// http://localhost:6200/users/42
// Method: "GET"
userAPI.Get("/:id", getByIDHandler)
// http://localhost:6200/users
// Method: "POST"
userAPI.Post("/", saveUserHandler)
}
// Start the server at 127.0.0.1:6200
app.Listen(":6200")
}
func getByIDHandler(ctx *iris.Context) {
// take the :id from the path, parse to integer
// and set it to the new userID local variable.
userID, _ := ctx.ParamInt("id")
// userRepo, imaginary database service <- your only job.
user := userRepo.GetByID(userID)
// send back a response to the client,
// .JSON: content type as application/json; charset="utf-8"
// iris.StatusOK: with 200 http status code.
//
// send user as it is or make use of any json valid golang type,
// like the iris.Map{"username" : user.Username}.
ctx.JSON(iris.StatusOK, user)
}
TIP: Execute
iris run main.go
to enable hot-reload on .go source code changes.
TIP: Add
templates.Reload(true)
to monitor the template changes.
Documentation
-
The most important is to read the practical guide
-
Read godocs for the details
-
Navigate through examples
-
HISTORY.md file is your best friend.
Testing
You can find RESTFUL test examples by navigating to the following links:
FAQ
Explore these questions and join to our community chat!
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. With support for the most used template engines (6+), you can quickly craft the perfect application.
People & Support
The author of Iris is @kataras.
The Success of Iris belongs to YOU with your bug reports and feature requests that made this Framework so Unique.
Who is kataras?
Hi, my name is Gerasimos Maropoulos and I'm the author of this project, let me put a few words about me.
I started to design Iris the night of the 13 March 2016, some weeks later, iris started to became famous and I have to fix many issues and implement new features, but I didn't have time to work on Iris because I had a part time job and the (software engineering) colleague which I studied.
I wanted to make iris' users proud of the framework they're using, so I decided to interrupt my studies and colleague, two days later I left from my part time job also.
Today I spend all my days and nights coding for Iris, and I'm happy about this, therefore I have zero incoming value.
- Star the project, will help you to follow the upcoming features.
- Donate, if you can afford any cost.
- Write an article about Iris or even post a Tweet.
- Do Pull Requests on the iris-contrib organisation's repositories, like book and examples.
If you are interested in contributing to the Iris project, please see the document CONTRIBUTING.
Contact
Besides the fact that we have a community chat for questions or reports and ideas, stackoverflow section for generic go+iris questions and the github issues for bug reports and feature requests, you can also contact with me, as a person who is always open to help you:
Versioning
Current: v6.2.0
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.
Note that some optional components that you may use with Iris requires different license agreements.