liar

package module
v0.0.0-...-2cce50d Latest Latest
Warning

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

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

README

Liar

Still a WIP. Simple Go middleware that serves different HTTP routes to clients if they are a bot. It currently only uses the client's user agent.

Installation

go get github.com/719ben/liar

Example

package main

import (
    "fmt"
    "github.com/719ben/liar"
    "net/http"
)

func humanHandler(w http.ResponseWriter, r *http.Request) {
    fmt.Fprintln(w, "You are a human, WUBBA LUBBA DUB DUB.")
}

func botHandler(w http.ResponseWriter, r *http.Request) {
    fmt.Fprintln(w, "You are a bot, I'm happy.")
}

func main() {
    newLiar := liar.NewFunc(botHandler)
    http.Handle("/", newLiar.HumanFunc(humanHandler))
    http.ListenAndServe(":8000", nil)
}

Contributions

I welcome all kinds of contributions.

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LiarRouter

type LiarRouter struct {
	// contains filtered or unexported fields
}

func New

func New(botHandler http.Handler) LiarRouter

func NewFunc

func NewFunc(f func(http.ResponseWriter, *http.Request)) LiarRouter

func (*LiarRouter) Human

func (LR *LiarRouter) Human(humanHandler http.Handler) http.Handler

func (*LiarRouter) HumanFunc

func (LR *LiarRouter) HumanFunc(f func(http.ResponseWriter, *http.Request)) http.Handler

Jump to

Keyboard shortcuts

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