2020-08-09 19:28:25 +02:00
[![Black Lives Matter ](https://iris-go.com/images/blacklivesmatter_banner.png )](https://support.eji.org/give/153413/#!/donation/checkout)
2020-08-09 19:23:18 +02:00
<!-- # News -->
2019-12-31 23:42:44 +01:00
2020-07-18 13:35:27 +02:00
> This is the under-**development branch**. Stay tuned for the upcoming release [v12.2.0](HISTORY.md#Next). Looking for a stable release? Head over to the [v12.1.8 branch](https://github.com/kataras/iris/tree/v12.1.8) instead.
2020-08-09 19:23:18 +02:00
>
> ![](https://iris-go.com/images/cli.png) Try the official [Iris Command Line Interface](https://github.com/kataras/iris-cli) today!
2020-04-29 20:59:36 +02:00
2020-06-20 23:12:07 +02:00
<!-- ![](https://iris-go.com/images/release.png) Iris version **12.1.8** has been [released ](HISTORY.md#su-16-february-2020--v1218 )! -->
2019-07-22 11:05:16 +02:00
2020-04-29 20:59:36 +02:00
# Iris Web Framework <a href="README_GR.md"><img width="20px" src="https://iris-go.com/images/flag-greece.svg" /></a> <a href="README_FR.md"><img width="20px" src="https://iris-go.com/images/flag-france.svg" /></a> <a href="README_ZH.md"><img width="20px" src="https://iris-go.com/images/flag-china.svg" /></a> <a href="README_ES.md"><img width="20px" src="https://iris-go.com/images/flag-spain.png" /></a> <a href="README_FA.md"><img width="20px" src="https://iris-go.com/images/flag-iran.svg" /></a> <a href="README_RU.md"><img width="20px" src="https://iris-go.com/images/flag-russia.svg" /></a> <a href="README_KO.md"><img width="20px" src="https://iris-go.com/images/flag-south-korea.svg?v=12" /></a>
2019-11-05 21:12:26 +01:00
2020-06-23 23:13:31 +02:00
[![build status ](https://img.shields.io/travis/kataras/iris/master.svg?style=for-the-badge&logo=travis )](https://travis-ci.org/kataras/iris) [![view examples ](https://img.shields.io/badge/examples%20-173-a83adf.svg?style=for-the-badge&logo=go )](https://github.com/kataras/iris/tree/master/_examples) [![chat ](https://img.shields.io/gitter/room/iris_go/community.svg?color=cc2b5e&logo=gitter&style=for-the-badge )](https://gitter.im/iris_go/community) <!--[![FOSSA Status](https://img.shields.io/badge/LICENSE%20SCAN-PASSING❤️ -CD2956?style=for-the-badge&logo=fossa)](https://app.fossa.io/projects/git%2Bgithub.com%2Fkataras%2Firis?ref=badge_shield)--> [![donate ](https://img.shields.io/badge/support-Iris-blue.svg?style=for-the-badge&logo=paypal )](https://iris-go.com/donate) <!--[![report card](https://img.shields.io/badge/report%20card-a%2B-ff3333.svg?style=for-the-badge)](https://goreportcard.com/report/github.com/kataras/iris)--><!--[![godocs](https://img.shields.io/badge/go-%20docs-488AC7.svg?style=for-the-badge)](https://pkg.go.dev/github.com/kataras/iris/v12@v12.2.0)--> <!-- [![release ](https://img.shields.io/badge/release%20-v12.0-0077b3.svg?style=for-the-badge )](https://github.com/kataras/iris/releases) -->
2018-07-24 03:33:53 +02:00
2020-07-28 12:56:52 +02:00
<!-- <a href="https://iris - go.com"> <img align="right" src="https://iris - go.com/images/logo - w169.png"></a> -->
2018-07-24 03:33:53 +02:00
2020-02-11 02:55:06 +01:00
Iris is a fast, simple yet fully featured and very efficient web framework for Go.
2020-02-11 02:24:57 +01:00
2020-02-11 02:55:06 +01:00
It provides a beautifully expressive and easy to use foundation for your next website or API.
2018-07-24 03:33:53 +02:00
2020-02-11 02:55:06 +01:00
Learn what [others saying about Iris ](https://iris-go.com/testimonials/ ) and ** [star ](https://github.com/kataras/iris/stargazers )** this open-source project to support its potentials.
2019-12-13 22:06:18 +01:00
2020-07-28 12:56:52 +02:00
[![ ](https://iris-go.com/images/reviews.gif )](https://iris-go.com/testimonials/)
2020-02-11 02:24:57 +01:00
2020-07-18 13:35:27 +02:00
[![Benchmarks: Jul 18, 2020 at 10:46am (UTC) ](https://iris-go.com/images/benchmarks.svg )](https://github.com/kataras/server-benchmarks)
2020-03-12 00:51:21 +01:00
2020-08-12 17:23:00 +02:00
## 👑 <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=7DPAYRDR28MMJ&item_name=Iris+Web+Framework¤cy_code=EUR&source=url">Supporters</a>
2020-08-12 17:32:33 +02:00
< p >
2020-08-18 18:02:20 +02:00
< a href = "https://github.com/AlbinoGeek" > < img src = "https://avatars1.githubusercontent.com/u/1910461?v=4" alt = "Damon Blais" title = "AlbinoGeek" with = "75" style = "width:75px;max-width:75px;height:75px" height = "75" / > < / a >
2020-08-12 17:32:33 +02:00
< a href = "https://github.com/LYF123123" > < img src = "https://avatars1.githubusercontent.com/u/33317812?v=4" alt = "陆 轶丰" title = "LYF123123" with = "75" style = "width:75px;max-width:75px;height:75px" height = "75" / > < / a >
< a href = "https://github.com/xiaozhuai" > < img src = "https://avatars1.githubusercontent.com/u/4773701?v=4" alt = "Weihang Ding" title = "xiaozhuai" with = "75" style = "width:75px;max-width:75px;height:75px" height = "75" / > < / a >
< a href = "https://github.com/fangli" > < img src = "https://avatars1.githubusercontent.com/u/3032639?v=4" alt = "Li Fang" title = "fangli" with = "75" style = "width:75px;max-width:75px;height:75px" height = "75" / > < / a >
< a href = "https://github.com/TechMaster" > < img src = "https://avatars1.githubusercontent.com/u/1491686?v=4" alt = "TechMaster" title = "TechMaster" with = "75" style = "width:75px;max-width:75px;height:75px" height = "75" / > < / a >
< a href = "https://github.com/lensesio" > < img src = "https://avatars1.githubusercontent.com/u/11728472?v=4" alt = "lenses.io" title = "lensesio" with = "75" style = "width:75px;max-width:75px;height:75px" height = "75" / > < / a >
< a href = "https://github.com/celsosz" > < img src = "https://avatars1.githubusercontent.com/u/3466493?v=4" alt = "Celso Souza" title = "celsosz" with = "75" style = "width:75px;max-width:75px;height:75px" height = "75" / > < / a >
< a href = "https://github.com/altafino" > < img src = "https://avatars1.githubusercontent.com/u/24539467?v=4" alt = "Altafino" title = "altafino" with = "75" style = "width:75px;max-width:75px;height:75px" height = "75" / > < / a >
< a href = "https://github.com/thomasfr" > < img src = "https://avatars1.githubusercontent.com/u/287432?v=4" alt = "Thomas Fritz" title = "thomasfr" with = "75" style = "width:75px;max-width:75px;height:75px" height = "75" / > < / a >
< a href = "https://github.com/hengestone" > < img src = "https://avatars1.githubusercontent.com/u/362587?v=4" alt = "Conrad Steenberg" title = "hengestone" with = "75" style = "width:75px;max-width:75px;height:75px" height = "75" / > < / a >
< a href = "https://github.com/se77en" > < img src = "https://avatars1.githubusercontent.com/u/1468284?v=4" alt = "Damon Zhao" title = "se77en" with = "75" style = "width:75px;max-width:75px;height:75px" height = "75" / > < / a >
< a href = "https://github.com/International" > < img src = "https://avatars1.githubusercontent.com/u/1022918?v=4" alt = "George Opritescu" title = "International" with = "75" style = "width:75px;max-width:75px;height:75px" height = "75" / > < / a >
< a href = "https://github.com/Juanses" > < img src = "https://avatars1.githubusercontent.com/u/6137970?v=4" alt = "Juanses" title = "Juanses" with = "75" style = "width:75px;max-width:75px;height:75px" height = "75" / > < / a >
< a href = "https://github.com/ansrivas" > < img src = "https://avatars1.githubusercontent.com/u/1695056?v=4" alt = "Ankur Srivastava" title = "ansrivas" with = "75" style = "width:75px;max-width:75px;height:75px" height = "75" / > < / a >
< a href = "https://github.com/lexrus" > < img src = "https://avatars1.githubusercontent.com/u/219689?v=4" alt = "Lex Tang" title = "lexrus" with = "75" style = "width:75px;max-width:75px;height:75px" height = "75" / > < / a >
< a href = "https://github.com/li3p" > < img src = "https://avatars1.githubusercontent.com/u/55519?v=4" alt = "li3p" title = "li3p" with = "75" style = "width:75px;max-width:75px;height:75px" height = "75" / > < / a >
2020-08-12 17:23:00 +02:00
< / p >
2020-02-11 02:24:57 +01:00
## 📖 Learning Iris
2019-07-22 04:46:30 +02:00
2018-07-25 05:14:33 +02:00
```sh
2020-01-05 17:27:21 +01:00
# https://github.com/kataras/iris/wiki/Installation
2020-06-20 23:12:07 +02:00
$ go get github.com/kataras/iris/v12@master
2020-06-23 23:13:31 +02:00
# assume the following code in main.go file
$ cat main.go
2018-07-25 05:14:33 +02:00
```
```go
package main
2019-10-25 00:27:02 +02:00
import "github.com/kataras/iris/v12"
2018-07-25 05:14:33 +02:00
func main() {
2020-07-20 12:36:39 +02:00
app := iris.New()
booksAPI := app.Party("/books")
{
booksAPI.Use(iris.Compression)
// GET: http://localhost:8080/books
booksAPI.Get("/", list)
// POST: http://localhost:8080/books
booksAPI.Post("/", create)
}
app.Listen(":8080")
2020-06-23 23:13:31 +02:00
}
2020-07-20 12:36:39 +02:00
// Book example.
type Book struct {
Title string `json:"title"`
}
func list(ctx iris.Context) {
books := []Book{
{"Mastering Concurrency in Go"},
{"Go Design Patterns"},
{"Black Hat Go"},
}
ctx.JSON(books)
// TIP: negotiate the response between server's prioritizes
// and client's requirements, instead of ctx.JSON:
// ctx.Negotiation().JSON().MsgPack().Protobuf()
// ctx.Negotiate(books)
}
func create(ctx iris.Context) {
var b Book
err := ctx.ReadJSON(& b)
// TIP: use ctx.ReadBody(& b) to bind
// any type of incoming data instead.
if err != nil {
ctx.StopWithProblem(iris.StatusBadRequest, iris.NewProblem().
Title("Book creation failure").DetailErr(err))
// TIP: use ctx.StopWithError(code, err) when only
// plain text responses are expected on errors.
return
}
println("Received Book: " + b.Title)
ctx.StatusCode(iris.StatusCreated)
2018-07-25 05:14:33 +02:00
}
```
2020-07-26 14:47:53 +02:00
**MVC** equivalent:
```go
import "github.com/kataras/iris/v12/mvc"
```
```go
m := mvc.New(booksAPI)
m.Handle(new(BookController))
```
```go
type BookController struct {
/* dependencies */
}
// GET: http://localhost:8080/books
func (c *BookController) Get() []Book {
return []Book{
{"Mastering Concurrency in Go"},
{"Go Design Patterns"},
{"Black Hat Go"},
}
}
// POST: http://localhost:8080/books
func (c *BookController) Post(b Book) int {
println("Received Book: " + b.Title)
return iris.StatusCreated
}
```
2020-07-20 12:36:39 +02:00
**Run** your Iris web server:
2019-07-22 11:05:16 +02:00
```sh
2020-06-23 23:13:31 +02:00
$ go run main.go
2020-07-20 12:36:39 +02:00
> Now listening on: http://localhost:8080
> Application started. Press CTRL+C to shut down.
```
**List** Books:
```sh
$ curl --header 'Accept-Encoding:gzip' http://localhost:8080/books
[
{
"title": "Mastering Concurrency in Go"
},
{
"title": "Go Design Patterns"
},
{
"title": "Black Hat Go"
}
]
```
**Create** a new Book:
```sh
$ curl -i -X POST \
--header 'Content-Encoding:gzip' \
--header 'Content-Type:application/json' \
--data "{\"title\":\"Writing An Interpreter In Go\"}" \
http://localhost:8080/books
> HTTP/1.1 201 Created
```
That's how an **error** response looks like:
```sh
$ curl -X POST --data "{\"title\" \"not valid one\"}" \
http://localhost:8080/books
> HTTP/1.1 400 Bad Request
{
"status": 400,
"title": "Book creation failure"
"detail": "invalid character '\"' after object key",
}
2018-07-25 05:14:33 +02:00
```
2019-07-22 04:46:30 +02:00
< / details >
2020-07-01 13:43:24 +02:00
[![run in the browser ](https://img.shields.io/badge/Run-in%20the%20Browser-348798.svg?style=for-the-badge&logo=repl.it )](https://bit.ly/2YJeSZe)
2020-06-23 23:13:31 +02:00
2019-07-22 04:46:30 +02:00
Iris contains extensive and thorough ** [wiki ](https://github.com/kataras/iris/wiki )** making it easy to get started with the framework.
2019-12-25 11:11:45 +01:00
<!-- ![](https://media.giphy.com/media/Ur8iqy9FQfmPuyQpgy/giphy.gif) -->
2019-11-14 19:16:34 +01:00
2020-06-20 23:12:07 +02:00
For a more detailed technical documentation you can head over to our [godocs ](https://godoc.org/github.com/kataras/iris ). And for executable code you can always visit the [./_examples ](_examples ) repository's subdirectory.
2019-07-22 03:39:14 +02:00
2019-07-22 04:46:30 +02:00
### Do you like to read while traveling?
2019-07-22 03:39:14 +02:00
2020-08-12 17:23:00 +02:00
< a href = "https://iris-go.com/#book" > < img alt = "Book cover" src = "https://iris-go.com/images/iris-book-cover-sm.jpg?v=12" / > < / a >
2019-07-30 17:02:02 +02:00
2020-08-12 23:52:33 +02:00
[![follow Iris web framework on twitter ](https://img.shields.io/twitter/follow/iris_framework?color=ee7506&logoColor=ee7506&style=for-the-badge&logo=twitter )](https://twitter.com/intent/follow?screen_name=iris_framework)
2020-08-18 22:14:11 +02:00
[![follow Iris web framework on facebook ](https://img.shields.io/badge/Follow%20%40Iris.framework-450-2D88FF.svg?style=for-the-badge&logo=facebook )](https://www.facebook.com/iris.framework)
2019-07-22 03:39:14 +02:00
2020-08-12 17:23:00 +02:00
You can [request ](https://iris-go.com/#book ) a PDF version and online access of the **E-Book** today and be participated in the development of Iris.
2018-07-24 03:33:53 +02:00
2020-02-11 02:24:57 +01:00
## 🙌 Contributing
2018-07-24 03:33:53 +02:00
2019-07-22 04:46:30 +02:00
We'd love to see your contribution to the Iris Web Framework! For more information about contributing to the Iris project please check the [CONTRIBUTING.md ](CONTRIBUTING.md ) file.
[List of all Contributors ](https://github.com/kataras/iris/graphs/contributors )
2020-02-11 02:24:57 +01:00
## 🛡 Security Vulnerabilities
2019-07-22 04:46:30 +02:00
If you discover a security vulnerability within Iris, please send an e-mail to [iris-go@outlook.com ](mailto:iris-go@outlook.com ). All security vulnerabilities will be promptly addressed.
2020-02-11 02:24:57 +01:00
## 📝 License
2018-07-24 03:33:53 +02:00
2020-02-03 09:50:58 +01:00
This project is licensed under the [BSD 3-clause license ](LICENSE ), just like the Go project itself.
2019-07-22 04:46:30 +02:00
2020-02-03 09:50:58 +01:00
The project name "Iris" was inspired by the Greek mythology.
2020-02-11 02:24:57 +01:00
<!-- ## Stargazers over time
2019-11-19 22:36:18 +01:00
2020-02-11 02:24:57 +01:00
[![Stargazers over time ](https://starchart.cc/kataras/iris.svg )](https://starchart.cc/kataras/iris) -->