ion

package module
v0.0.0-...-28d43d2 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2020 License: MIT Imports: 4 Imported by: 0

README

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 (
	"fmt"
	"github.com/estebarb/ion"
	"net/http"
)

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.

License

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

Documentation

Overview

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

This framework is based on https://blog.gopheracademy.com/advent-2016/go-syntax-for-dsls/ 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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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 "".

Types

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

Directories

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

Jump to

Keyboard shortcuts

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