github kataras/iris v14.0.0

one hour ago

Iris v14 is the first new major version since v12. The module path is github.com/kataras/iris/v14 and it requires Go 1.27 or later.

go get github.com/kataras/iris/v14@v14.0.0
package main

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

type Book struct {
	Title string `json:"title"`
}

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

	app.Get("/books/{id:uuid}", func(ctx iris.Context) {
		ctx.JSON(iris.Map{"id": ctx.Params().GetString("id")})
	})

	app.Post("/books", func(ctx iris.Context) {
		book, ok := ctx.BindJSON[Book]()
		if !ok {
			return
		}

		ctx.StatusCode(iris.StatusCreated)
		ctx.JSON(book)
	})

	app.Listen(":8080")
}

ctx.BindJSON[Book]() is a generic method, which is why v14 needs Go 1.27. It decodes the body, runs Validate() error when the type has one, and answers the client itself when either step fails.

What is new

  • iris.NewBuilder assembles an application in one compile-checked chain: CORS, compression, access logging, a health endpoint, error mapping, services and API groups.
  • Typed request binding on generic methods (ctx.BindJSON[T](), ctx.BindUpdate[T]()) replaces hand-written decode blocks.
  • rest/errors: handlers report errors and one central map turns them into canonical, machine-readable responses. Internal details go to the server log and never to the client.
  • A dependency injection container is built in and replaces hero. Constructors declare what they need, Initializer hooks run at startup and closers run at shutdown.
  • JSON runs on encoding/json/v2.
  • Thirty-one built-in middleware, API keys being the newest. Sessions, cache, i18n, versioning and websocket now live under middleware/.
  • Authentication at every scale: Basic Auth typed by your own user type, API keys, a generic JWT SDK, an identity server and an OAuth2 provider.
  • ai: renders and relays streamed model output over HTTP (text deltas, reasoning traces, tool-call fragments, usage). It is provider-agnostic and ships no vendor SDK.
  • client: an HTTP client for calling other services under the same JSON rules the server side uses.
  • Views are a middleware. middleware/view holds a one-method Engine interface. The HTML, Django, Handlebars, Jet, Pug and Ace engines moved to iris-contrib/views, and kataras/blocks works as it is.
  • Server options: app.Run(iris.ServerOptions{...}) replaces iris.Addr, iris.TLS and iris.AutoTLS. ngrok tunneling is opt-in through a blank import of core/server/ngrok.
  • MVC controllers on Go generics, in controller/mvc.

Upgrading from v12

Every removed v12 name fails at compile time, so the compiler's error list is your to-do list. MIGRATION.md maps each name to its replacement. It opens with a prompt that you can paste into a coding agent, which then does the mechanical part.

The replacements most applications meet first:

v12 v14
github.com/kataras/iris/v12 github.com/kataras/iris/v14
iris.Party, app.Party(prefix) iris.Router, app.Router(prefix)
iris.Configuration, iris.With... iris.Options
iris.Addr, iris.TLS, iris.AutoTLS app.Run(iris.ServerOptions{...})
ctx.URLParam("q") ctx.Query().Get("q")
ctx.Params().Get("id") ctx.Params().GetString("id")
ctx.Header(k, v) to set, ctx.GetHeader(k) to read ctx.SetHeader(k, v) to set, ctx.Header(k) to read
app.RegisterView(engine), ctx.View(...) app.Use(view.Handler(engine)), view.Render(ctx, ...)
hero the built-in DI container
middleware/logger middleware/accesslog
middleware/recover middleware/recovery
sessions, cache, websocket, i18n, view, versioning the same names under middleware/
mvc controller/mvc
x/errors, x/client, x/jsonx rest/errors, client, rest/types

Defaults that changed

The compiler does not flag these, so read them before you deploy:

  • Session cookies are Secure and SameSite=Lax.
  • JWT tokens are read from the Authorization header only.
  • CORS no longer advertises credentials together with a wildcard origin.
  • ctx.SetCookie replaces a cookie with the same name, path and domain, and ctx.AddCookie defaults to SameSite=Lax.
  • JSON is encoded and decoded by encoding/json/v2.

MIGRATION.md explains each one, and lists the v12 bugs whose fixes change what you observe.

v12

Nothing changes for an application that imports github.com/kataras/iris/v12. That code stays on the v12 branch, and v12.2.12 is its latest release.

Documentation

Related repositories

Found a problem? Open an issue.

Don't miss a new iris release

NewReleases is sending notifications on new releases.