Beispiel #1
0
func main() {
	flag.Parse()
	log.Printf("Starting server, os.Args=%s", strings.Join(os.Args, " "))
	if err := readSecrets(); err != nil {
		log.Fatal(err)
	}

	var err error
	templateSet, err = parseTemplates(*templateDir)
	if err != nil {
		log.Fatal(err)
	}

	db, err = database.New()
	if err != nil {
		log.Fatal(err)
	}

	if *popularInterval > 0 {
		go updatePopularPackages(*popularInterval)
	}

	if *crawlInterval > 0 {
		go crawl(*crawlInterval)
	}

	sfo := &web.ServeFileOptions{
		Header: web.Header{
			web.HeaderCacheControl: {"public, max-age=3600"},
		},
	}

	r := web.NewRouter()
	r.Add("/").GetFunc(serveHome)
	r.Add("/-/about").GetFunc(serveAbout)
	r.Add("/-/go").GetFunc(serveGoIndex)
	r.Add("/-/index").GetFunc(serveIndex)
	r.Add("/-/refresh").PostFunc(serveRefresh)
	r.Add("/-/static/<path:.*>").Get(web.DirectoryHandler(*staticDir, sfo))
	r.Add("/robots.txt").Get(web.FileHandler(filepath.Join(*staticDir, "robots.txt"), nil))
	r.Add("/humans.txt").Get(web.FileHandler(filepath.Join(*staticDir, "humans.txt"), nil))
	r.Add("/favicon.ico").Get(web.FileHandler(filepath.Join(*staticDir, "favicon.ico"), nil))
	r.Add("/google3d2f3cd4cc2bb44b.html").Get(web.FileHandler(filepath.Join(*staticDir, "google3d2f3cd4cc2bb44b.html"), nil))
	r.Add("/about").Get(web.RedirectHandler("/-/about", 301))
	r.Add("/a/index").Get(web.RedirectHandler("/-/index", 301))
	r.Add("/C").Get(web.RedirectHandler("http://golang.org/doc/articles/c_go_cgo.html", 301))
	r.Add("/<path:.*>").GetFunc(servePackage)
	h := web.ErrorHandler(handleError, web.FormAndCookieHandler(1000, false, r))
	listener, err := net.Listen("tcp", *httpAddr)
	if err != nil {
		log.Fatal("Listen", err)
		return
	}
	defer listener.Close()
	s := &server.Server{Listener: listener, Handler: h} // add logger
	err = s.Serve()
	if err != nil {
		log.Fatal("Server", err)
	}
}
Beispiel #2
0
func main() {
	flag.Parse()
	log.Printf("Starting server, os.Args=%s", strings.Join(os.Args, " "))

	var err error
	templateSet, err = parseTemplates(*templateDir)
	if err != nil {
		log.Fatal(err)
	}

	db, err = database.New()
	if err != nil {
		log.Fatal(err)
	}

	freq = popularity.NewFrequent(10)
	recent = popularity.NewRecent(10)

	go crawl()

	sfo := &web.ServeFileOptions{
		Header: web.Header{
			web.HeaderCacheControl: {"public, max-age=3600"},
		},
	}

	r := web.ErrorHandler(handleError,
		web.FormAndCookieHandler(1000, false, web.NewRouter().
			AddGet("/", serveHome).
			AddGet("/-/about", serveAbout).
			AddGet("/-/go", serveGoIndex).
			AddGet("/-/index", serveIndex).
			AddPost("/-/refresh", serveRefresh).
			AddGet("/-/static/<path:.*>", web.DirectoryHandler(*staticDir, sfo)).
			AddGet("/robots.txt", web.FileHandler(filepath.Join(*staticDir, "robots.txt"), nil)).
			AddGet("/favicon.ico", web.FileHandler(filepath.Join(*staticDir, "favicon.ico"), nil)).
			AddGet("/google3d2f3cd4cc2bb44b.html", web.FileHandler(filepath.Join(*staticDir, "google3d2f3cd4cc2bb44b.html"), nil)).
			AddGet("/about", web.RedirectHandler("/-/about", 301)).
			AddGet("/a/index", web.RedirectHandler("/-/index", 301)).
			AddGet("/C", web.RedirectHandler("http://golang.org/doc/articles/c_go_cgo.html", 301)).
			AddGet("/<path:.*>", servePackage)))

	listener, err := net.Listen("tcp", *httpAddr)
	if err != nil {
		log.Fatal("Listen", err)
		return
	}
	defer listener.Close()
	s := &server.Server{Listener: listener, Handler: r} // add logger
	err = s.Serve()
	if err != nil {
		log.Fatal("Server", err)
	}
}
Beispiel #3
0
func main() {
	flag.Parse()
	log.Printf("Starting server, os.Args=%s", strings.Join(os.Args, " "))
	if err := readSecrets(); err != nil {
		log.Fatal(err)
	}

	if err := parseHTMLTemplates([][]string{
		{"about.html", "common.html", "skeleton.html"},
		{"bot.html", "common.html", "skeleton.html"},
		{"cmd.html", "common.html", "skeleton.html"},
		{"home.html", "common.html", "skeleton.html"},
		{"importers.html", "common.html", "skeleton.html"},
		{"imports.html", "common.html", "skeleton.html"},
		{"index.html", "common.html", "skeleton.html"},
		{"notfound.html", "common.html", "skeleton.html"},
		{"pkg.html", "common.html", "skeleton.html"},
		{"results.html", "common.html", "skeleton.html"},
		{"std.html", "common.html", "skeleton.html"},
		{"graph.html", "common.html"},
	}); err != nil {
		log.Fatal(err)
	}

	if err := parseTextTemplates([][]string{
		{"cmd.txt", "common.txt"},
		{"home.txt", "common.txt"},
		{"notfound.txt", "common.txt"},
		{"pkg.txt", "common.txt"},
		{"results.txt", "common.txt"},
	}); err != nil {
		log.Fatal(err)
	}

	if err := parsePresentTemplates([][]string{
		{".article", "article.tmpl", "action.tmpl"},
		{".slide", "slides.tmpl", "action.tmpl"},
	}); err != nil {
		log.Fatal(err)
	}

	present.PlayEnabled = true

	var err error
	db, err = database.New()
	if err != nil {
		log.Fatal(err)
	}

	if *popularInterval > 0 {
		go updatePopularPackages(*popularInterval)
	}

	if *crawlInterval > 0 {
		go crawl(*crawlInterval)
	}

	sfo := &web.ServeFileOptions{
		Header: web.Header{
			web.HeaderCacheControl: {"public, max-age=3600"},
		},
	}

	r := web.NewRouter()
	r.Add("/").GetFunc(servePresentHome)
	r.Add("/compile").PostFunc(serveCompile)
	r.Add("/favicon.ico").Get(web.FileHandler(filepath.Join(*baseDir, "static", "favicon.ico"), nil))
	r.Add("/google3d2f3cd4cc2bb44b.html").Get(web.FileHandler(filepath.Join(*baseDir, "static", "google3d2f3cd4cc2bb44b.html"), nil))
	r.Add("/humans.txt").Get(web.FileHandler(filepath.Join(*baseDir, "static", "humans.txt"), nil))
	r.Add("/play.js").Get(web.CatFilesHandler(sfo, filepath.Join(*presentBaseDir, "js"), "jquery.js", "playground.js", "play.js"))
	r.Add("/robots.txt").Get(web.FileHandler(filepath.Join(*baseDir, "static", "presentRobots.txt"), nil))
	r.Add("/static/<path:.*>").Get(web.DirectoryHandler(filepath.Join(*presentBaseDir, "static"), sfo))
	r.Add("/<path:.+>").GetFunc(servePresentation)

	h := web.NewHostRouter()
	h.Add("talks.<:.*>", web.ErrorHandler(handlePresentError, web.FormAndCookieHandler(6000, false, r)))

	r = web.NewRouter()
	r.Add("/").GetFunc(serveHome)
	r.Add("/-/about").GetFunc(serveAbout)
	r.Add("/-/bot").GetFunc(serveBot)
	r.Add("/-/go").GetFunc(serveGoIndex)
	r.Add("/-/index").GetFunc(serveIndex)
	r.Add("/-/refresh").PostFunc(serveRefresh)
	r.Add("/-/static/<path:.*>").Get(web.DirectoryHandler(filepath.Join(*baseDir, "static"), sfo))
	r.Add("/a/index").Get(web.RedirectHandler("/-/index", 301))
	r.Add("/about").Get(web.RedirectHandler("/-/about", 301))
	r.Add("/favicon.ico").Get(web.FileHandler(filepath.Join(*baseDir, "static", "favicon.ico"), nil))
	r.Add("/google3d2f3cd4cc2bb44b.html").Get(web.FileHandler(filepath.Join(*baseDir, "static", "google3d2f3cd4cc2bb44b.html"), nil))
	r.Add("/humans.txt").Get(web.FileHandler(filepath.Join(*baseDir, "static", "humans.txt"), nil))
	r.Add("/robots.txt").Get(web.FileHandler(filepath.Join(*baseDir, "static", "robots.txt"), nil))
	r.Add("/C").Get(web.RedirectHandler("http://golang.org/doc/articles/c_go_cgo.html", 301))
	r.Add("/<path:.+>").GetFunc(servePackage)

	h.Add("<:.*>", web.ErrorHandler(handleError, web.FormAndCookieHandler(1000, false, r)))

	listener, err := net.Listen("tcp", *httpAddr)
	if err != nil {
		log.Fatal("Listen", err)
		return
	}
	defer listener.Close()
	s := &server.Server{Listener: listener, Handler: h} // add logger
	err = s.Serve()
	if err != nil {
		log.Fatal("Server", err)
	}
}