コード例 #1
0
ファイル: main.go プロジェクト: tenntenn/gomoxy
func main() {
	var proxy *goproxy.ProxyHttpServer
	app.Main(func(a app.App) {
		var sz size.Event
		for e := range a.Events() {
			switch e := app.Filter(e).(type) {
			case lifecycle.Event:
				if e.Crosses(lifecycle.StageAlive) == lifecycle.CrossOn && proxy == nil {
					proxy = goproxy.NewProxyHttpServer()
					//proxy.Verbose = true
					re := regexp.MustCompile(`.*`)
					proxy.OnResponse(goproxy.UrlMatches(re)).DoFunc(
						func(res *http.Response, ctx *goproxy.ProxyCtx) *http.Response {
							if label != nil {
								label.Text = fmt.Sprintf("%s\n%s\n", ctx.Req.URL, label.Text)
								log.Println(ctx.Req.URL)
							}
							return res
						})
					go func() {
						log.Fatal(http.ListenAndServe(":8888", proxy))
					}()
				}
			case paint.Event:
				onPaint(sz)
				a.EndPaint(e)
			case size.Event:
				sz = e
			}
		}
	})
}