New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

github.com/h4tr3d/iris

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/h4tr3d/iris

  • v6.0.0+incompatible
  • Source
  • Go
  • Socket score

Version published
Created
Source

Navigate to http://support.iris-go.com

Build Status http://goreportcard.com/report/kataras/iris Iris support forum Examples for new Gophers Docs Chat Buy me a cup of coffee
Iris is an efficient and well-designed, cross-platform, web framework with robust set of features.
Build your own high-performance web applications and APIs powered by unlimited potentials and portability.

If you're coming from Node.js world, this is the expressjs equivalent for the Go Programming Language.

Feature Overview

  • Focus on high performance
  • Automatically install and serve certificates from https://letsencrypt.org
  • Robust routing and middleware ecosystem
  • Build RESTful APIs
  • Choose your favorite routes' path syntax between httprouter and gorillamux
  • Request-Scoped Transactions
  • Group API's and subdomains with wildcard support
  • Body binding for JSON, XML, Forms, can be extended to use your own custom binders
  • More than 50 handy functions to send HTTP responses
  • View system: supporting more than 6+ template engines, with prerenders. You can still use your favorite
  • Define virtual hosts and (wildcard) subdomains with path level routing
  • Graceful shutdown
  • Limit request body
  • Localization i18N
  • Serve static files
  • Cache
  • Log requests
  • Customizable format and output for the logger
  • Customizable HTTP errors
  • Compression (Gzip)
  • Authentication
  • OAuth, OAuth2 supporting 27+ popular websites
  • JWT
  • Basic Authentication
  • HTTP Sessions
  • Add / Remove trailing slash from the URL with option to redirect
  • Redirect requests
  • HTTP to HTTPS
  • HTTP to HTTPS WWW
  • HTTP to HTTPS non WWW
  • Non WWW to WWW
  • WWW to non WWW
  • Highly scalable rich content render (Markdown, JSON, JSONP, XML...)
  • Websocket-only API similar to socket.io
  • Hot Reload on source code changes
  • Typescript integration + Web IDE
  • Checks for updates at startup
  • Highly customizable
  • Feels like you used iris forever, thanks to its Fluent API
  • And many others...

Table of Contents

Installation

The only requirement is the Go Programming Language, at least 1.8

$ go get gopkg.in/iris-framework/iris.v6

For further installation support, navigate here.

Overview

package main

import (
	"gopkg.in/iris-framework/iris.v6"
	"gopkg.in/iris-framework/iris.v6/adaptors/cors"
	"gopkg.in/iris-framework/iris.v6/adaptors/httprouter"
	"gopkg.in/iris-framework/iris.v6/adaptors/view"
)

func main() {
	// Receives optional iris.Configuration{}, see ./configuration.go
	// for more.
	app := iris.New()

	// Order doesn't matter,
	// You can split it to different .Adapt calls.
	// See ./adaptors folder for more.
	app.Adapt(
		// adapt a logger which prints all errors to the os.Stdout
		iris.DevLogger(),
		// adapt the adaptors/httprouter or adaptors/gorillamux
		httprouter.New(),
		// 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"
		view.HTML("./views", ".html"),
		// Cors wrapper to the entire application, allow all origins.
		cors.New(cors.Options{AllowedOrigins: []string{"*"}}))

	// http://localhost:6300
	// Method: "GET"
	// Render ./views/index.html
	app.Get("/", func(ctx *iris.Context) {
		ctx.Render("index.html", iris.Map{"Title": "Page Title"}, iris.RenderOptions{"gzip": true})
	})

	// 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:6300/users/*anything
		userAPI.OnError(404, userNotFoundHandler)

		// http://localhost:6300/users
		// Method: "GET"
		userAPI.Get("/", getAllHandler)

		// http://localhost:6300/users/42
		// Method: "GET"
		userAPI.Get("/:id", getByIDHandler)

		// http://localhost:6300/users
		// Method: "POST"
		userAPI.Post("/", saveUserHandler)
	}

	// Start the server at 127.0.0.1:6300
	app.Listen(":6300")
}

func userAPIMiddleware(ctx *iris.Context) {
	// your code here...
	println("Request: " + ctx.Path())
	ctx.Next() // go to the next handler(s)
}

func userNotFoundHandler(ctx *iris.Context) {
	// your code here...
	ctx.HTML(iris.StatusNotFound, "<h1> User page not found </h1>")
}

func getAllHandler(ctx *iris.Context) {
	// your code here...
}

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)
}

func saveUserHandler(ctx *iris.Context) {
	// your code here...
}

Reload on source code changes

$ go get -u github.com/kataras/rizla
$ cd $GOPATH/src/mywebapp
$ rizla main.go

Reload templates on each incoming request

app.Adapt(view.HTML("./views", ".html").Reload(true))

FAQ & Documentation

  1. Getting Started with Go+Iris

  2. Official small but practical examples

  3. Navigate through community examples too

  4. Creating A URL Shortener Service Using Go, Iris, and Bolt

  5. Godocs for deep documentation

  6. HISTORY.md is your best friend, version migrations are released there

I'll be glad to talk with you about your awesome feature requests, open a new discussion, you will be heard!

Third Party Middleware

Iris has its own middleware form of func(ctx *iris.Context) but it's also compatible with all net/http middleware forms using iris.ToHandler, i.e Negroni's middleware form of func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc).

Here is a small list of Iris compatible middleware, I'm sure you can find more:

MiddlewareAuthorDescription
bindingMatt HoltData binding from HTTP requests into structs
cloudwatchColin SteeleAWS cloudwatch metrics middleware
cspAwake NetworksContent Security Policy (CSP) support
delayJeff MartinezAdd delays/latency to endpoints. Useful when testing effects of high latency
New Relic Go AgentYadvendar ChampawatOfficial New Relic Go Agent (currently in beta)
gorelicJingwen Owen OuNew Relic agent for Go runtime
JWT MiddlewareAuth0Middleware checks for a JWT on the Authorization header on incoming requests and decodes it
logrusDan BuchLogrus-based logger
ontheflyAlexander RødsethGenerate TinySVG, HTML and CSS on the fly
permissions2Alexander RødsethCookies, users and permissions
prometheusRene ZbindenEasily create metrics endpoint for the prometheus instrumentation tool
renderCory JacobsenRender JSON, XML and HTML templates
RestGatePrasanga SiripalaSecure authentication for REST API endpoints
secureCory JacobsenMiddleware that implements a few quick security wins
statsFlorent MessaStore information about your web application (response time, etc.)
VanGoHTaylor WrobelConfigurable AWS-Style HMAC authentication middleware
xrequestidAndrea FranzMiddleware that assigns a random X-Request-Id header to each request
digitsBilal AmarniMiddleware that handles Twitter Digits authentication

Feel free to put up a PR your middleware!

Testing

The httptest package is a simple Iris helper for the httpexpect, a new library for End-to-end HTTP and REST API testing for Go.

You can find tests by navigating to the source code, i.e:

A simple test is located to ./_examples/advanced/httptest/main_test.go

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. Iris is routerless which means you can adapt any router you like, httprouter is the fastest, gorillamux has more features. With support for the most used template engines (5), you can quickly craft the perfect application.

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.

FAQs

Package last updated on 17 Apr 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc