andrew-d / wolf-old

Simple little boilerplate around httprouter and net/context

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

wolf

GoDoc Build Status Coverage Status

A very simple (~200 LoC) web "framework" that simply integrates httprouter and x/net/context.

Example

package main

import (
	"fmt"
	"log"
	"net/http"

	"github.com/andrew-d/wolf"
	"golang.org/x/net/context"
)

func main() {
	m := wolf.New()

	m.Use(myMiddleware)

	m.Get("/", func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
		fmt.Fprintln(w, "Hello world")
	})

	log.Println("Started")
	http.ListenAndServe(":3001", m)
}

func myMiddleware(ctx *context.Context, h http.Handler) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		log.Printf("Got request to: %s", r.URL)
		h.ServeHTTP(w, r)
	})
}

License

MIT

About

Simple little boilerplate around httprouter and net/context


Languages

Language:Go 100.0%