示例#1
0
func (p *proxy) Start() {
	mux := http.NewServeMux()
	mux.Handle("/", p)

	log.Printf("Starting proxy at %s\n", p.Address)
	log.Fatal(gracehttp.Serve(&http.Server{Handler: mux, Addr: p.Address}))
}
示例#2
0
文件: demo.go 项目: rubyist/go.grace
func main() {
	flag.Parse()
	gracehttp.Serve(
		&http.Server{Addr: *address0, Handler: newHandler("Zero  ")},
		&http.Server{Addr: *address1, Handler: newHandler("First ")},
		&http.Server{Addr: *address2, Handler: newHandler("Second")},
	)
}
示例#3
0
func (p *proxy) Start() {
	mux := http.NewServeMux()
	mux.Handle("/", p)
	p.Transport = &http.Transport{DisableKeepAlives: false, DisableCompression: false}

	log.Printf("Starting proxy at %s\n", p.Address)
	log.Fatal(gracehttp.Serve(&http.Server{Handler: mux, Addr: p.Address}))
}
示例#4
0
文件: web.go 项目: mattwkelly/rell
func main() {
	flag.Usage = flagconfig.Usage
	flag.Parse()
	flagconfig.Parse()
	runtime.GOMAXPROCS(*goMaxProcs)
	err := gracehttp.Serve(
		gracehttp.Handler{*mainAddress, mainHandler()},
		gracehttp.Handler{*adminAddress, adminHandler()},
	)
	if err != nil {
		log.Fatal(err)
	}
}
示例#5
0
func main() {
	var httpAddr, httpsAddr string
	flag.StringVar(&httpAddr, "http", ":48560", "http address to bind to")
	flag.StringVar(&httpsAddr, "https", ":48561", "https address to bind to")
	flag.Parse()

	// we have self signed certs
	http.DefaultTransport = &http.Transport{
		DisableKeepAlives: true,
		TLSClientConfig: &tls.Config{
			InsecureSkipVerify: true,
		},
	}

	err := flag.Set("gracehttp.log", "false")
	if err != nil {
		log.Fatalf("Error setting gracehttp.log: %s", err)
	}

	// print json to stderr once we can successfully connect to all three
	// addresses. the ensures we only print the line once we're ready to serve.
	go func() {
		var wg sync.WaitGroup
		wg.Add(2)
		go wait(&wg, fmt.Sprintf("http://%s/sleep/?duration=0", httpAddr))
		go wait(&wg, fmt.Sprintf("https://%s/sleep/?duration=0", httpsAddr))
		wg.Wait()

		err = json.NewEncoder(os.Stderr).Encode(&response{Pid: os.Getpid()})
		if err != nil {
			log.Fatalf("Error writing startup json: %s", err)
		}
	}()

	err = gracehttp.Serve(
		&http.Server{Addr: httpAddr, Handler: newHandler()},
		httpsServer(httpsAddr),
	)
	if err != nil {
		log.Fatalf("Error in gracehttp.Serve: %s", err)
	}
}
示例#6
0
文件: grid.go 项目: daaku/go.testgrid
func main() {
	flag.Parse()
	flagconfig.Parse()
	pidfile.Write()

	proxyDriver := &Proxy{
		Headless:        *headless,
		SharedBaseDisk:  *sharedBaseDisk,
		NumMachines:     *numMachines,
		DefaultVideoRam: *defaultVideoRam,
		DefaultMemory:   *defaultMemory,
		VirtualboxHome:  *vboxHome,
	}
	proxyDriver.Init()

	err := gracehttp.Serve(
		gracehttp.Handler{Addr: *serverAddress, Handler: proxyDriver})
	if err != nil {
		log.Fatalf("gracehttp.Serve: %s", err)
	}
}