| 1 |
package main |
| 2 |
|
| 3 |
import ( |
| 4 |
"github.com/elazarl/goproxy" |
| 5 |
"log" |
| 6 |
"net/http" |
| 7 |
"time" |
| 8 |
) |
| 9 |
|
| 10 |
func main() { |
| 11 |
proxy := goproxy.NewProxyHttpServer() |
| 12 |
proxy.OnRequest(goproxy.DstHostIs("www.reddit.com")).DoFunc( |
| 13 |
func(r *http.Request, ctx *goproxy.ProxyCtx) (*http.Request, *http.Response) { |
| 14 |
h, _, _ := time.Now().Clock() |
| 15 |
if h >= 8 && h <= 17 { |
| 16 |
return r, goproxy.NewResponse(r, |
| 17 |
goproxy.ContentTypeText, http.StatusForbidden, |
| 18 |
"Don't waste your time!") |
| 19 |
} else { |
| 20 |
ctx.Warnf("clock: %d, you can waste your time...", h) |
| 21 |
} |
| 22 |
return r, nil |
| 23 |
}) |
| 24 |
log.Fatalln(http.ListenAndServe(":8080", proxy)) |
| 25 |
} |