glug

package module
v0.0.0-...-25d0a7b Latest Latest
Warning

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

Go to latest
Published: May 1, 2017 License: MIT Imports: 0 Imported by: 0

README

Glug

GoDoc Go Report Card

Inspired by Plug and Rack this package provides simple router which allows you to aggregate functions into pipelines for each endpoint. Pipelines are built with:

Conn (struct)
type Conn struct {
	Writer  http.ResponseWriter
	Request *http.Request
	Params  url.Values
}

Contains all request related data through plugs in pipeline.

Plug (function)
type Plug func(Conn) Conn

Should modify Conn or Halt() pipeline.

Getting Started

go get -u github.com/droptheplot/glug

Usage

package main

import (
	"github.com/droptheplot/glug"
	"fmt"
	"net/http"
)

func Root(conn glug.Conn) glug.Conn {
	fmt.Fprintf(conn.Writer, "Everyone can access this page.")
	return conn
}

func BlogIndex(conn glug.Conn) glug.Conn {
	fmt.Fprintf(conn.Writer, "Nothing to see here!")
	return conn
}

func Auth(conn glug.Conn) glug.Conn {
	http.Redirect(conn.Writer, conn.Request, "/", http.StatusFound)
	return conn.Halt()
}

func main() {
	r := glug.New()
	r.HandleFunc("GET", "/", Root)
	r.HandleFunc("GET", "/blog", Auth, BlogIndex)
	http.ListenAndServe(":3000", r)
}

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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