コード例 #1
0
ファイル: server.go プロジェクト: wemanity-belgium/hyperclair
//Serve run a local server with the fileserver and the reverse proxy
func Serve(sURL string) error {

	go func() {

		http.Handle("/v2/", newSingleHostReverseProxy())
		http.Handle("/local/", http.StripPrefix("/local", restrictedFileServer(docker.TmpLocal())))

		listener := tcpListener(sURL)
		logrus.Info("Starting Server on ", listener.Addr())

		if err := http.Serve(listener, nil); err != nil {
			logrus.Fatalf("local server error: %v", err)
		}
	}()
	//sleep needed to wait the server start. Maybe use a channel for that
	time.Sleep(5 * time.Millisecond)
	return nil
}
コード例 #2
0
ファイル: server.go プロジェクト: jgsqware/hyperclair
func Serve(sURL string) error {
	go func() {
		restrictedFileServer := func(path string) http.Handler {
			if _, err := os.Stat(path); os.IsNotExist(err) {
				os.Mkdir(path, 0777)
			}

			fc := func(w http.ResponseWriter, r *http.Request) {
				http.FileServer(http.Dir(path)).ServeHTTP(w, r)
			}
			return http.HandlerFunc(fc)
		}

		router.PathPrefix("/v1/local").Handler(http.StripPrefix("/v1/local", restrictedFileServer(docker.TmpLocal()))).Methods("GET")

		ListenAndServe(sURL)
	}()
	//sleep needed to wait the server start. Maybe use a channel for that
	time.Sleep(5 * time.Millisecond)
	return nil
}