iris README

The project's README from github.com/kataras/iris. As one markdown file: README.md.

News

🚀 Iris v14 is on the way. The next major version is the largest release in the project's history: the framework rebuilt on Go generics, an application builder the compiler checks, request helpers that validate for you, one central error map, thirty built-in middleware and a book that ships inside the repository. See what is coming in Iris v14 below.

The version you are reading about here, v12, keeps working and keeps getting fixes. v14 arrives on a new import path, so nothing on your side breaks the day it lands.

Iris Web Framework العربية

build status view examples chat donate

⚡ Iris is a fast, simple yet fully featured and very efficient web framework for Go.

✨ It provides a beautifully expressive and easy to use foundation for your next website or API.

🌟 Learn what others say about Iris and star this open-source project

Benchmarks: Jul 18, 2020 at 10:46am (UTC)

package main

import "github.com/kataras/iris/v12"

func main() {
  app := iris.New()
  app.Use(iris.Compression)

  app.Get("/", func(ctx iris.Context) {
    ctx.HTML("Hello <strong>%s</strong>!", "World")
  })

  app.Listen(":8080")
}

As one Go developer once said, Iris got you covered all-round and standing strong over the years ⭐

Some of the features Iris offers:

🚀 What is coming in Iris v14

Iris v14 is the largest release in the project's history. It rebuilds the framework on Go generics and changes how an application is put together: less wiring in main, shorter handlers, and one place for the decisions that used to be scattered across every route.

None of it needs your attention today. v12 keeps working, keeps getting fixes, and v14 arrives with a migration guide that covers every renamed and removed API.

The whole application in one compile-checked chain

iris.NewBuilder wires CORS, compression, access logging, the health endpoint, the error map, your services and your API groups in a single expression. The compiler enforces the step order, so an application either builds correctly or does not build at all.

iris.NewBuilder().
    Prefix("/api").
    AllowOrigin("*").
    Compression(true).
    LogRequests(true).
    Health(true, "production", "kataras").
    Errors(errors.NewOptions().
        MapErrors(errors.NotFound, catalog.ErrNotFound)).
    Services(catalog.NewRepository, catalog.NewService).
    API("/products", api.NewProductsAPI).
    Build().
    Listen(":8080")

Handlers stop repeating themselves

Decoding, validation and error rendering move out of the handler body. rest.ReadJSON[T] decodes the request, runs the type's Validate() error when it has one, and writes the 400 itself. The response helpers write the success status, or whatever your central map says that error should return.

func (api *ProductsAPI) create(ctx iris.Context) {
    input, ok := rest.ReadJSON[catalog.ProductInput](ctx)
    if !ok {
        return // 400 already written: malformed JSON or failed Validate.
    }

    id, err := api.svc.Create(ctx, input)
    rest.Created(ctx, id, err) // 201, or the centrally mapped error.
}

rest.OK, rest.NoContent, rest.Count and rest.Paginated cover the rest of the shapes an API returns.

Errors are declared once

The new rest/errors package holds the mapping from your domain errors to HTTP responses. Clients get canonical, machine-readable payloads. Internal messages stay internal. Register a collector and every failure reaches your logger or your database from a single place. An error can render as JSON or as a view, depending on what the client asked for.

Dependency injection everywhere, not only in MVC

Constructors declare what they need and the container provides it: for handlers, for API groups, for controllers. A service that implements Init(ctx context.Context) error runs once inside Build(). Anything closeable is closed at shutdown. The hero package is gone, replaced by dep and rest, which do more in fewer lines. MVC controllers are built on generics.

The packages are where you would expect them

sessions, cache, websocket, i18n, view and versioning became middleware. mvc moved under controller, next to the new fileserver, sitemap and apigraph controllers. apigraph renders your route tree as an interactive D3 graph.

Thirty middleware ship in the box, including new ones: httpcost (time, memory and CPU per request, for performance work or billing), bodylimit, compress, counter, referrer, geolocation, ipaccess and servertiming. View engine implementations moved to iris-contrib/views.

Configuration is a partial literal

iris.Configuration and the With* configurators are replaced by iris.Options. Set the fields you care about and the rest come from the defaults. Bind loads YAML from the SERVER_CONFIG environment variable, then from a file.

app := iris.New(iris.Options{Name: "myapp", LogLevel: "debug"})

Names that say what they do

Reading a request header and setting a response header no longer share a prefix that quietly flips meaning: ctx.Header reads the request, ctx.SetHeader and ctx.ResponseHeader work on the response. Party is now Router. ctx.URLParam is now ctx.Query().Get. Every rename is listed in the migration guide with its replacement, and most are one search and replace.

Secure by default

Session cookies ship with Secure and SameSite=Lax. The request body limit is enforced on every read path. Long-standing bugs went down with the rebuild, among them a rate limiter that recorded limits without ever enforcing them and a Logout call that could take the process with it.

Documentation you can read start to finish

v14 comes with a book of 23 chapters inside the repository, a getting started tutorial that builds a tested REST API in one document, a migration guide for v12 applications, and a live AI wiki generated from the source that answers questions about the codebase.

What it means for your v12 code

The import path becomes github.com/kataras/iris/v14, so v12 and v14 can sit side by side and nothing breaks on release day. Upgrade when it suits you. The migration guide covers the import path, the package moves, every removed API and its replacement, and the behavior changes, with ready commands for the mechanical parts.

There is no public release date yet. Watch releases or follow @iris_framework to hear about it first.

👑 Supporters

With your help, we can improve Open Source web development for everyone!

getsentry github lensesio thepunterbot h4rdc0m draFWM gf3 trading-peter AlbinoGeek basilarchia sumjoe simpleittools xiaozhuai Remydeme celsosz linxcoder jnelle TechMaster janwebdev altafino jakoubek alekperos day0ng hengestone thomasfr code-chimp CetinBasoz International Juanses <

iris (kataras/iris)

Searching Database…

25.6K ·GitHub
这是什么?Iris 是一个用于 Go 的开源 Web 框架,用来搭建网站和 API。它号称速度快、功能全、容易上手,自带 MVC、会话(session)、WebSocket 以及大量内置中间件。
它是框架还是库?是一个完整的 Web 框架,而不是一个轻量工具库:它负责路由、中间件、配置和控制器,还自带依赖注入容器和测试套件。
怎么把它加到我的 Go 项目里?用 go get github.com/kataras/iris/v12@latest 把模块拉进项目,导入后注册路由即可。即将发布的 v14 会改用 github.com/kataras/iris/v14 这个导入路径,所以 v12 和 v14 可以并存。
除了 Go,构建和运行 Iris 应用还需要别的东西吗?只需要 Go 工具链——Iris 应用可以编译成一个独立的可执行文件。如果想快速把开发服务器暴露出去,它还内置了 ngrok 支持,可以直接把应用发布到互联网上。
现在适合采用它吗?v12 是当前的主线版本,仍在持续修复问题,但一个大版本的 v14 即将到来:新的导入路径、被改名和移除的 API,而且公开发布时间还没定。届时会有一份迁移指南来帮助升级。
开箱即用能拿到哪些东西?很多:HTTP/2、API 版本管理、WebSocket、gRPC、自动 HTTPS、缓存、国际化(i18n)、会话、支持类型化路径参数(:uuid、:int)的路由,以及 CORS、JWT、basicauth、限流、panic 恢复和访问日志等中间件。
Iris v14 有什么变化?基于 Go 泛型重写:编译器能检查的应用构建器(iris.NewBuilder)、负责解码并校验请求的 rest.ReadJSON[T]、统一集中的错误映射、处处可用的依赖注入、三十个中间件,仓库里还有一本 23 章的教程书。
它能渲染 HTML 模板,还是只能做 JSON API?两者都可以。视图引擎支持 HTML、Django、Handlebars 和 Pug/Jade 模板,富响应格式还包括 JSON、XML、YAML、Markdown、Protocol Buffers、MessagePack、流式传输和服务器推送事件。
我是写普通的 handler 函数,还是用 MVC 控制器?都行。你可以注册普通的 handler 函数,也可以使用 MVC 控制器,而且依赖注入对两者都适用——handler、API 路由和控制器都可以声明自己需要的依赖。
What are similar projects?echo, beego, fiber, martini, sails, carno.js, angular.js, fastify
Creator
kataras
Size
18 MB
Stars
25.6K
Age
10y
Commits · 90 Days