Ion Web Framework

GoDoc Build Status codecov Go Report Card

Ion is a small web framework written in Go.

Ion leverages component composition to allow functionality reuse, and build complex behaviors based on simple components.

A short example:

package main

import (

func newApp() http.Handler {
    routes := ion.Routes{
        "/:name": {
            Middleware:  []ion.Middleware{ion.PathEnd},
            HttpHandler: http.HandlerFunc(hello),
    return routes.Build()

func hello(w http.ResponseWriter, r *http.Request) {
    name := r.Context().Value("name")
    if name != "" {
        fmt.Fprintf(w, "Hello, %v!", name)
    } else {
        fmt.Fprint(w, "Hello world!")

func main() {
    app := newApp()
    http.ListenAndServe(":5500", app)

At this point the framework is highly experimental, so please take that in consideration if you want to use it.


Ion is released under the MIT License, as specified in LICENSE.

Expand ▾ Collapse ▴



Package ion implements a small web framework that allows to easily connect reusable components.

This framework is based on idea of using a DSL. This approach naturally removes the need to implement a router, allowing the framework to just reuse Go standard mux.

Ion have the following features:

- Can use easily any http.Handler or http.HandlerFunc - Easily describe paths (with arguments) and method handlers - Compatible with Middlewares - Use context for passing path arguments



This section is empty.


This section is empty.


func PathEnd

func PathEnd(handler http.Handler) http.Handler

PathEnd is a middleware used to "cut" the requests path at the current level. The request is handled if the path is "/" or "".


type Builder

type Builder interface {
	Build() http.Handler

Builder interface is implemented by objects that can be build into an http.Handler

type Chain

type Chain []Middleware

Chain describes a secuence of Middleware

func (Chain) Then

func (c Chain) Then(h http.Handler) http.Handler

Then composes all the middlewares wrapping the given http.Handler, and returns a new http.Handler

type Endpoint

type Endpoint struct {
	Middleware  []Middleware
	Handler     Builder
	HttpHandler http.Handler

Endpoint describes a http request handler, that may have optional Middleware

func (Endpoint) Build

func (e Endpoint) Build() http.Handler

Build generates an http.Handler from an Endpoint

type Methods

type Methods map[string]Endpoint

Methods implement an http.Handler that handles requests according to the request method.

func (Methods) Build

func (m Methods) Build() http.Handler

Build generates an http.Handler

type Middleware

type Middleware func(next http.Handler) http.Handler

Middleware is a function that wrap an http.Handler and returns a value that implements the http.Handler interface

type Routes

type Routes map[string]Endpoint

Routes describe a request router that handles request according to its path

func (Routes) Build

func (r Routes) Build() http.Handler

Build returns an http.Handler that can handle requests by path

Source Files


Path Synopsis
components/router Package router contains a flexible router, with integrated context management per request
futures Package futures allow adding incomplete computations in contexts and templates.
middleware Package middleware contains general purpose middleware.
middleware/hotcache Package hotcache intercepts and group equal requests, perform a single server request.