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) } }
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) } }
func del(c *command) { if len(c.flag.Args()) != 1 { c.printUsage() os.Exit(1) } db, err := database.New() if err != nil { log.Fatal(err) } if err := db.Delete(c.flag.Args()[0]); err != nil { log.Fatal(err) } }
func main() { flag.Parse() db, err := database.New() if err != nil { log.Fatal(err) } var n int err = db.Do(func(pdoc *doc.Package, pkgs []database.Package) error { n += 1 return db.Put(pdoc) }) if err != nil { log.Fatal(err) } log.Printf("Updated %d documents.", n) }
func reindex(c *command) { if len(c.flag.Args()) != 0 { c.printUsage() os.Exit(1) } db, err := database.New() if err != nil { log.Fatal(err) } var n int err = db.Do(func(pi *database.PackageInfo) error { n += 1 return db.Put(pi.PDoc) }) if err != nil { log.Fatal(err) } log.Printf("Updated %d documents", n) }
func main() { flag.Parse() db, err := database.New() if err != nil { log.Fatal(err) } var n int err = db.Do(func(pdoc *doc.Package, pkgs []database.Package) error { n += 1 if pdoc.IsCmd && pdoc.Synopsis == "" && len(pkgs) == 0 { log.Println("delete empty command", pdoc.ImportPath) return db.Delete(pdoc.ImportPath) } if pdoc.Name == "" && len(pkgs) == 0 { log.Println("delete empty dir", pdoc.ImportPath) return db.Delete(pdoc.ImportPath) } return db.Put(pdoc) }) if err != nil { log.Fatal(err) } log.Printf("Updated %d documnts", n) }
func prune(c *command) { if len(c.flag.Args()) != 0 { c.printUsage() os.Exit(1) } db, err := database.New() if err != nil { log.Fatal(err) } paths := make(map[string]bool) err = db.Do(func(pi *database.PackageInfo) error { pdoc := pi.PDoc if pdoc.ProjectRoot == "" { return nil } i := strings.LastIndex(pdoc.ImportPath, "/") if i < 0 { return nil } suffix := pdoc.ImportPath[i:] imports := make(map[string]bool) for _, p := range pdoc.Imports { imports[p] = true } pathLists := [][]string{pdoc.TestImports, pdoc.XTestImports, pdoc.References} if pdoc.ProjectRoot != pdoc.ImportPath { if pdocRoot, _, _ := db.GetDoc(pdoc.ProjectRoot); pdocRoot != nil { pathLists = append(pathLists, pdocRoot.References) } } fork := "" forkCheck: for _, list := range pathLists { for _, p := range list { if p != pdoc.ImportPath && strings.HasSuffix(p, suffix) && !imports[p] { pdocTest, _, _ := db.GetDoc(p) if pdocTest != nil && pdocTest.Name == pdoc.Name && jaccardIndex(pdocTest, pdoc) > 0.75 { fork = pdocTest.ImportPath break forkCheck } } } } if fork != "" { log.Printf("%s is fork of %s", pdoc.ImportPath, fork) if !*pruneDryRun { for _, pkg := range pi.Pkgs { if err := db.Delete(pkg.Path); err != nil { log.Printf("Error deleting %s, %v", pkg.Path, err) } } if err := db.Delete(pdoc.ImportPath); err != nil { log.Printf("Error deleting %s, %v", pdoc.ImportPath, err) } } } else { keep := pi.Rank > 0 if pdoc.IsCmd && pdoc.Synopsis != "" && len(pdoc.Doc) > len(pdoc.Synopsis) { // Keep a command if there's actually some documentation. keep = true } p := pdoc.ImportPath for { paths[p] = paths[p] || keep if len(p) <= len(pdoc.ProjectRoot) { break } else if i := strings.LastIndex(p, "/"); i < 0 { break } else { p = p[:i] } } } return nil }) for p, keep := range paths { if !keep { log.Printf("%s has rank 0", p) if !*pruneDryRun { if err := db.Delete(p); err != nil { log.Printf("Error deleting %s, %v", p, err) } } } } if err != nil { log.Fatal(err) } }
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) } }