Skip to content

Instantly share code, notes, and snippets.

@ijt ijt/focus.go
Created Oct 8, 2012

Embed
What would you like to do?
Web proxy that disallows distracting websites
package main
import (
"flag"
"fmt"
"github.com/elazarl/goproxy"
"log"
"net/http"
"os"
)
func main() {
flag.Parse()
if flag.NArg() != 1 {
fmt.Println("usage: focus PORT")
os.Exit(1)
}
portStr := flag.Arg(0)
proxy := goproxy.NewProxyHttpServer()
proxy.Verbose = true
blacklist := []string {
"www.reddit.com",
"news.ycombinator.com",
"www.youtube.com",
}
for _, host := range(blacklist) {
proxy.OnRequest(goproxy.DstHostIs(host)).DoFunc(scold)
}
log.Fatal(http.ListenAndServe(":" + portStr, proxy))
}
func scold(r *http.Request,ctx *goproxy.ProxyCtx)(*http.Request,*http.Response) {
return r, goproxy.NewResponse(r, goproxy.ContentTypeText,http.StatusForbidden,
"Don't waste your time!")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.