slim

package module
v0.0.0-...-4d0ef35 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2014 License: MIT Imports: 7 Imported by: 0

README

Slim

GoDoc Build Status

Slim is a fork of Goji, a minimalistic web framework that values composability and simplicity.

Differences with Goji

func(ctx context.Context, w http.ResponseWriter, r *http.Request, next web.Handler)

Example

package main

import (
        "fmt"
        "net/http"

        "code.google.com/p/go.net/context"
        "github.com/vanackere/slim"
        "github.com/vanackere/slim/web"
)

func hello(ctx context.Context, w http.ResponseWriter, r *http.Request) {
        p := web.URLParams(ctx)
        fmt.Fprintf(w, "Hello, %s!", p["name"])
}

func main() {
        slim.Get("/hello/:name", hello)
        slim.Serve()
}

Slim also includes a sample application in the example folder which was artificially constructed to show off all of Slim's features. Check it out!

Features

  • Fork of the excellent Goji framework
  • Compatible with net/http
  • URL patterns (both Sinatra style /foo/:bar patterns and regular expressions, as well as custom patterns)
  • Reconfigurable middleware stack
  • Context/environment object threaded through middleware and handlers
  • Context is the one from "code.google.com/p/go.net/context" (see here for an introduction)
  • Automatic support for Einhorn, systemd, and more
  • Graceful shutdown, and zero-downtime graceful reload when combined with Einhorn.

See Goji's README for why Goji's - and therore Slim's ! - approach is good.

Documentation

Overview

Package slim provides an out-of-box web server with reasonable defaults.

Example:

package main

import (
	"fmt"
	"net/http"

	"code.google.com/p/go.net/context"

	"github.com/vanackere/slim"
	"github.com/vanackere/slim/web"
)

func hello(c context.Context, w http.ResponseWriter, r *http.Request) {
	fmt.Fprintf(w, "Hello, %s!", web.URLParams(c)["name"])
}

func main() {
	slim.Get("/hello/:name", hello)
	slim.Serve()
}

This package exists purely as a convenience to programmers who want to get started as quickly as possible. It draws almost all of its code from slim's subpackages, the most interesting of which is slim/web, and where most of the documentation for the web framework lives.

A side effect of this package's ease-of-use is the fact that it is opinionated. If you don't like (or have outgrown) its opinions, it should be straightforward to use the APIs of slim's subpackages to reimplement things to your liking. Both methods of using this library are equally well supported.

Slim requires Go 1.2 or newer.

Index

Constants

This section is empty.

Variables

View Source
var DefaultMux *web.Mux

The default web.Mux.

Functions

func Abandon

func Abandon(middleware interface{}) error

Abandon removes the given middleware from the default Mux's middleware stack. See the documentation for web.Mux.Abandon for more information.

func Connect

func Connect(pattern interface{}, handler interface{})

Connect adds a CONNECT route to the default Mux. See the documentation for web.Mux for more information about what types this function accepts.

func Delete

func Delete(pattern interface{}, handler interface{})

Delete adds a DELETE route to the default Mux. See the documentation for web.Mux for more information about what types this function accepts.

func Get

func Get(pattern interface{}, handler interface{})

Get adds a GET route to the default Mux. See the documentation for web.Mux for more information about what types this function accepts.

func Handle

func Handle(pattern interface{}, handler interface{})

Handle adds a route to the default Mux. See the documentation for web.Mux for more information about what types this function accepts.

func Head(pattern interface{}, handler interface{})

Head adds a HEAD route to the default Mux. See the documentation for web.Mux for more information about what types this function accepts.

func Insert

func Insert(middleware, before interface{}) error

Insert the given middleware into the default Mux's middleware stack. See the documentation for web.Mux.Insert for more information.

func NotFound

func NotFound(handler interface{})

NotFound sets the NotFound handler for the default Mux. See the documentation for web.Mux.NotFound for more information.

func Options

func Options(pattern interface{}, handler interface{})

Options adds a OPTIONS route to the default Mux. See the documentation for web.Mux for more information about what types this function accepts.

func Patch

func Patch(pattern interface{}, handler interface{})

Patch adds a PATCH route to the default Mux. See the documentation for web.Mux for more information about what types this function accepts.

func Post

func Post(pattern interface{}, handler interface{})

Post adds a POST route to the default Mux. See the documentation for web.Mux for more information about what types this function accepts.

func Put

func Put(pattern interface{}, handler interface{})

Put adds a PUT route to the default Mux. See the documentation for web.Mux for more information about what types this function accepts.

func Serve

func Serve()

Serve starts Goji using reasonable defaults.

func Trace

func Trace(pattern interface{}, handler interface{})

Trace adds a TRACE route to the default Mux. See the documentation for web.Mux for more information about what types this function accepts.

func Use

func Use(middleware interface{})

Use appends the given middleware to the default Mux's middleware stack. See the documentation for web.Mux.Use for more information.

Types

This section is empty.

Directories

Path Synopsis
Package bind provides a convenient way to bind to sockets.
Package bind provides a convenient way to bind to sockets.
Command example is a sample application built with Goji.
Command example is a sample application built with Goji.
Package graceful implements graceful shutdown for HTTP servers by closing idle connections after receiving a signal.
Package graceful implements graceful shutdown for HTTP servers by closing idle connections after receiving a signal.
web
Package web implements a fast and flexible middleware stack and mux.
Package web implements a fast and flexible middleware stack and mux.
middleware
Package middleware provides several standard middleware implementations.
Package middleware provides several standard middleware implementations.
util
Package util contains various functions that are helpful when writing http middleware.
Package util contains various functions that are helpful when writing http middleware.

Jump to

Keyboard shortcuts

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