ion: github.com/estebarb/ion Index | Files | Directories

package ion

import "github.com/estebarb/ion"

Package ion is a small web framework written in Go.

Ion provides a request router, middleware management, automatic context support and some handful helpers.

A short example:

package main

import (
	"fmt"
	"github.com/estebarb/ion"
	"github.com/estebarb/ion/components/router"
	"net/http"
)

func hello(w http.ResponseWriter, r *http.Request) {
	context := ion.App.Context(r)
	params := context.(router.IPathParam)
	value, exists := params.PathParams()["name"]
	if exists {
		fmt.Fprintf(w, "Hello, %v!", value)
	} else {
		fmt.Fprint(w, "Hello world!")
	}
}

func main() {
	ion.GetFunc("/", hello)
	ion.GetFunc("/:name", hello)
	http.ListenAndServe(":5500", ion.App)
}

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

Index

Package Files

ion.go

func Delete Uses

func Delete(path string, handler http.Handler) *router.Route

Delete register a Delete action in the default application

func DeleteFunc Uses

func DeleteFunc(path string, handler http.HandlerFunc) *router.Route

DeleteFunc register a DeleteFunc action in the default application

func DoNothing Uses

func DoNothing(w http.ResponseWriter, r *http.Request)

DoNothing is a handler that do nothing. It can be used as a placeholder, or when we want to run the middleware for the collateral effects, but we don't want to do something specific. Also can be used with IonMVC.

func Get Uses

func Get(path string, handler http.Handler) *router.Route

Get register a Get action in the default application

func GetFunc Uses

func GetFunc(path string, handler http.HandlerFunc) *router.Route

GetFunc register a GetFunc action in the default application

func MarshalJSON Uses

func MarshalJSON(w http.ResponseWriter, value interface{}) error

MarshalJSON writes a JSON value to the ResponseWriter

func MethodHandle Uses

func MethodHandle(method, path string, handle http.Handler) *router.Route

MethodHandle registers a request handler for the given path, and adds the current middleware in Ion settings.

func MethodHandleFunc Uses

func MethodHandleFunc(method, path string, handle http.HandlerFunc) *router.Route

MethodHandleFunc registers a request handler for the given path, and adds the current middleware in Ion settings.

func Patch Uses

func Patch(path string, handler http.Handler) *router.Route

Patch register a Patch action in the default application

func PatchFunc Uses

func PatchFunc(path string, handler http.HandlerFunc) *router.Route

PatchFunc register a PatchFunc action in the default application

func Post Uses

func Post(path string, handler http.Handler) *router.Route

Post register a Post action in the default application

func PostFunc Uses

func PostFunc(path string, handler http.HandlerFunc) *router.Route

PostFunc register a PostFunc action in the default application

func Put Uses

func Put(path string, handler http.Handler) *router.Route

Put register a Put action in the default application

func PutFunc Uses

func PutFunc(path string, handler http.HandlerFunc) *router.Route

PutFunc register a PutFunc action in the default application

func ServeHTTP Uses

func ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP calls ion.App.ServeHTTP(w, r), the request dispatcher of the default Ion application.

func UnmarshalJSON Uses

func UnmarshalJSON(r *http.Request, value interface{}) error

UnmarshalJSON parses the request body as a JSON value

type Ion Uses

type Ion struct {
    *router.Router
    Middleware []*chain.Chain
}

Ion represents an Ion web application

var App *Ion

App is the default Ion application created when importing the package. Instead of creating and passing a ion.Ion instance in the application this global variable could be used.

func New Uses

func New(contextFactory func() interface{}) *Ion

New creates an Ion application, with router and middleware support. It receives a contextFactory that creates a context per request.

func (*Ion) Delete Uses

func (a *Ion) Delete(path string, handler http.Handler) *router.Route

Delete register the handler in the router, after wrapping it with the middleware

func (*Ion) DeleteFunc Uses

func (a *Ion) DeleteFunc(path string, handler http.HandlerFunc) *router.Route

DeleteFunc register the handler in the router, after wrapping it with the middleware

func (*Ion) Get Uses

func (a *Ion) Get(path string, handler http.Handler) *router.Route

Get register the handler in the router, after wrapping it with the middleware

func (*Ion) GetFunc Uses

func (a *Ion) GetFunc(path string, handler http.HandlerFunc) *router.Route

GetFunc register the handler in the router, after wrapping it with the middleware

func (*Ion) MethodHandle Uses

func (a *Ion) MethodHandle(method, path string, handle http.Handler) *router.Route

MethodHandle registers a request handler for the given path, and adds the current middleware in Ion settings.

func (*Ion) MethodHandleFunc Uses

func (a *Ion) MethodHandleFunc(method, path string, handle http.HandlerFunc) *router.Route

MethodHandleFunc registers a request handler for the given path, and adds the current middleware in Ion settings.

func (*Ion) Patch Uses

func (a *Ion) Patch(path string, handler http.Handler) *router.Route

Patch register the handler in the router, after wrapping it with the middleware

func (*Ion) PatchFunc Uses

func (a *Ion) PatchFunc(path string, handler http.HandlerFunc) *router.Route

PatchFunc register the handler in the router, after wrapping it with the middleware

func (*Ion) Post Uses

func (a *Ion) Post(path string, handler http.Handler) *router.Route

Post register the handler in the router, after wrapping it with the middleware

func (*Ion) PostFunc Uses

func (a *Ion) PostFunc(path string, handler http.HandlerFunc) *router.Route

PostFunc register the handler in the router, after wrapping it with the middleware

func (*Ion) Put Uses

func (a *Ion) Put(path string, handler http.Handler) *router.Route

Put register the handler in the router, after wrapping it with the middleware

func (*Ion) PutFunc Uses

func (a *Ion) PutFunc(path string, handler http.HandlerFunc) *router.Route

PutFunc register the handler in the router, after wrapping it with the middleware

func (*Ion) RegisterREST Uses

func (a *Ion) RegisterREST(path string, handler RESTendpoint)

RegisterREST register a RESTendpoint in the router with some default paths It will register the following routes:

- GET  path		(list function)
- POST path		(post function)
- GET  path/:id	        (get function)
- PUT  path/:id	        (put function)
- DELETE  path/:id	(delete function)

The path MUST include the trailing slash.

type RESTendpoint Uses

type RESTendpoint interface {
    LIST(w http.ResponseWriter, r *http.Request)
    POST(w http.ResponseWriter, r *http.Request)
    PUT(w http.ResponseWriter, r *http.Request)
    GET(w http.ResponseWriter, r *http.Request)
    DELETE(w http.ResponseWriter, r *http.Request)
}

RESTendpoint works with RegisterREST to provide a shortcut to register an RESTful endpoint.

Directories

PathSynopsis
components/chainPackage chain provides functions for managing chains of middleware that can be used to provide reusable functionality that wraps http Handlers.
components/ionrwPackage ionrw contains a http.ResponseWriter implementation
components/renderPackage render provides a little sugar to the usage of standard Go templates.
components/reqctxPackage reqctx provides an uniform way to access request context.
components/routerPackage router contains a flexible router, with integrated context management per request
examples/hello
examples/restful
futuresPackage futures allow adding incomplete computations in contexts and templates.
middlewarePackage middleware contains general purpose middleware.
middleware/hotcachePackage hotcache intercepts and group equal requests, perform a single server request.

Package ion imports 5 packages (graph) and is imported by 2 packages. Updated 2017-02-02. Refresh now. Tools for package owners.