2019-09-04 10:29:52 +00:00
|
|
|
package requests
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
"os/exec"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/elazarl/goproxy"
|
|
|
|
)
|
|
|
|
|
2019-09-04 16:50:44 +00:00
|
|
|
const ProxyAddress = "localhost:58080"
|
2019-09-04 10:29:52 +00:00
|
|
|
|
|
|
|
func init() {
|
|
|
|
log.SetFlags(log.Lshortfile | log.LstdFlags)
|
|
|
|
go func() {
|
|
|
|
proxy := goproxy.NewProxyHttpServer()
|
|
|
|
proxy.Verbose = true
|
|
|
|
http.ListenAndServe(ProxyAddress, proxy)
|
|
|
|
}()
|
|
|
|
|
|
|
|
cmd := exec.Command("/bin/bash", "-c", "docker ps | grep httpbin")
|
|
|
|
_, err := cmd.Output()
|
|
|
|
if err != nil {
|
2019-09-04 16:50:44 +00:00
|
|
|
log.Println("recommend 1. docker run -p 80:80 kennethreitz/httpbin \n2. echo \"127.0.0.1 httpbin.org\" >> /etc/hosts")
|
2019-09-04 10:29:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
time.Sleep(time.Millisecond * 100)
|
|
|
|
}
|