std-interop

command
v14.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 12, 2026 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

Standard library interop: net/http handlers inside Iris, and the Iris application inside a plain http.Server.

Iris converts in both directions.

iris.FromStd turns anything net/http-shaped into an iris.Handler: an http.Handler value, a func(w, r) or a middleware-shaped func(w, r, next http.HandlerFunc). That is how packages like net/http/pprof, expvar or promhttp mount on an Iris route.

In the other direction, *iris.Application implements http.Handler once Build has run, so it drops into any standard server, test harness or third-party listener. app.Listen and app.Run call Build for you; call it yourself only when handing the application to infrastructure you own, as below.

The hand-written key check at the bottom is here only to have a piece of net/http middleware to adapt; a real API key belongs to middleware/apikey, which compares in constant time and renders the framework's 401 envelope.

Learn: mount any net/http handler or middleware on an Iris route, and serve the Iris application from your own http.Server.

Run:

go run main.go

Try:

curl http://localhost:8080/                                   # 200 {"served_by":"net/http","framework":"iris"}
curl http://localhost:8080/healthz                            # 200 ok
curl http://localhost:8080/debug/vars                         # 200, expvar JSON
curl -i http://localhost:8080/guarded                         # 401 from the net/http middleware
curl -i -H "X-Api-Key: k3y" http://localhost:8080/guarded     # 200 {"secret":42}

Next: ../typed-context

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL