func newRecommender() recommend.Recommender { var categoryList data.CategoryList if flagCategoryFile == "" { list, err := crawler.GetCategoryList() if err != nil { glog.Fatalf("Failed to crawl category list: %v", err) } categoryList = list } else { categoryList = loadCategoryFile() } return recommend.NewRandomRecommender(categoryList, ImgDir) }
func main() { if flagCategory { categoryList, err := crawler.GetCategoryList() if err != nil { glog.Fatalf("Failed to crawl category list: %v", err) } printJson(categoryList) return } if flagRecommend { printJson(newRecommender().Do()) return } // CLI code paths must be at above. if flagWeb { http.Handle("/img/", app.ImgHandler(path.Dir(ImgDir), http.FileServer(http.Dir(path.Dir(ImgDir))))) http.HandleFunc("/", app.Handler(newRecommender())) glog.Infof(fmt.Sprintf("Starting a web server at localhost:%d", flagPort)) glog.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", flagPort), http.DefaultServeMux)) } }