Skip to content

droptheplot/glug

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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)
}

Releases

No releases published

Packages

No packages published

Languages