Esempio n. 1
0
func main() {
	flag.Usage = usage
	flag.Parse()

	switch {
	default:
		fmt.Println("Using all Go packages in GOPATH.")
		goPackages = &exp14.GoPackages{SkipGoroot: true} // All Go packages in GOPATH (not including GOROOT).
		updater = repo.GopathUpdater{GoPackages: goPackages}
	case *stdinFlag:
		fmt.Println("Reading the list of newline separated Go packages from stdin.")
		goPackages = &exp14.GoPackagesFromReader{Reader: os.Stdin}
		updater = repo.GopathUpdater{GoPackages: goPackages}
	case *godepsFlag != "":
		fmt.Println("Reading the list of Go packages from Godeps.json file:", *godepsFlag)
		goPackages = newGoPackagesFromGodeps(*godepsFlag)
		updater = nil
	case *govendorFlag != "":
		fmt.Println("Reading the list of Go packages from vendor.json file:", *govendorFlag)
		goPackages = newGoPackagesFromGovendor(*govendorFlag)
		updater = nil
	}

	err := loadTemplates()
	if err != nil {
		log.Fatalln("loadTemplates:", err)
	}

	http.HandleFunc("/index.html", mainHandler)
	http.Handle("/favicon.ico", http.NotFoundHandler())
	http.Handle("/assets/", gzip_file_server.New(assets))
	http.Handle("/opened", websocket.Handler(openedHandler)) // Exit server when client tab is closed.
	if updater != nil {
		http.HandleFunc("/-/update", updateHandler)
		go updateWorker()
	}

	// Start listening first.
	listener, err := net.Listen("tcp", *httpFlag)
	if err != nil {
		log.Fatalf("failed to listen on %q: %v\n", *httpFlag, err)
	}

	switch production {
	case true:
		// Open a browser tab and navigate to the main page.
		go u4.Open("http://" + *httpFlag + "/index.html")
	case false:
		updater = repo.MockUpdater{}
	}

	fmt.Println("Go Package Store server is running at http://" + *httpFlag + "/index.html.")

	err = http.Serve(listener, nil)
	if err != nil {
		log.Fatalln(err)
	}
}
Esempio n. 2
0
func main() {
	flag.Parse()

	http.HandleFunc("/", mainHandler)
	http.Handle("/assets/", gzip_file_server.New(assets))
	http.Handle("/favicon.ico", http.NotFoundHandler())

	printServingAt(*httpFlag)
	err := http.ListenAndServe(*httpFlag, nil)
	if err != nil {
		log.Fatalln("ListenAndServe:", err)
	}
}