Skip to content

Community driven successor of the iris web framework

License

Notifications You must be signed in to change notification settings

glycerine/iris2

Repository files navigation

Iris2

Build Status Go Report Card GoDoc codecov codebeat badge

Iris2 is a fork of the original Iris framework. As Iris, Iris2 is an efficient and complete toolbox with robust set of features.
Write your own perfect high-performance web applications
with unlimited potentials and portability.
Iris2 aims for a stable API and be easy to use.

Installation

The only requirement is the Go Programming Language, version 1.8+

$ go get github.com/go-iris2/iris2

Overview

package main

import (
	"net/http"

	"github.com/go-iris2/iris2"
	"github.com/go-iris2/iris2/adaptors/view"
)

func main() {
	app := iris2.New()
	app.Adapt(iris2.Devlogger())

	// 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"
	templates := view.HTML("./views", ".html")
	app.Adapt(templates)

	// http://localhost:6200
	// Method: "GET"
	// Render ./views/index.html
	app.Get("/", func(ctx *iris2.Context) {
		ctx.Render("index.html", nil)
	})

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

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

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

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

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

func getByIDHandler(ctx *iris2.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"
	// http.StatusOK: with 200 http status code.
	//
	// send user as it is or make use of any json valid golang type,
	// like the iris2.Map{"username" : user.Username}.
	ctx.JSON(http.StatusOK, user)
}

Versioning

Iris2 adheres to Semantic Versioning.

See the Changelog.

License

Unless otherwise noted, the source files are distributed under the MIT License found in the LICENSE.

About

Community driven successor of the iris web framework

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages