Exemple #1
0
func main() {
	flag.Parse()
	c := NewController(timeout)
	var s blogplus.Storage
	var err error
	if driver == "memory" {
		s = blogplus.NewMemStorage()
	} else {
		if initDb {
			blogplus.InitDB(driver, datasource)
		}
		s, err = blogplus.NewDBStorage(driver, datasource)
		if err != nil {
			panic(err)
		}
	}
	s.SetFilter(blogplus.IsMeaningfulPost)
	fetcher := blogplus.NewFetcher(userId, key)

	b := blogplus.NewBlogplus(s, c)
	b.Title = title
	b.AuthorName = authorName
	b.AuthorUri = authorUri
	b.Scheme = scheme
	if host == "" {
		b.Host = "localhost" + addr
	} else {
		b.Host = host
	}
	b.SetStaticDir(staticDir)
	if dumpTemplate {
		if templateDir == "" {
			panic("need template_dir")
		}
		fmt.Printf("Extracting template in %s...", templateDir)
		b.ExtractTemplates(templateDir)
		fmt.Println("done")
		return
	}
	if templateDir != "" {
		b.LoadTemplates(templateDir)
	}

	go c.Run(fetcher, s)
	http.Handle("/", b)
	log.Println("start serving ", addr)
	err = http.ListenAndServe(addr, nil)
	if err != nil {
		log.Fatal(err)
	}
}
Exemple #2
0
func main() {
	flag.Parse()
	fetcher := blogplus.NewFetcher(userId, key)
	fmt.Printf("%#v\n", fetcher)
	b := bufio.NewReader(os.Stdin)
	for {
		line, err := b.ReadString('\n')
		if err != nil {
			break
		}
		fmt.Println(line)
		if line == "" {
			fetcher.Fetch(&http.Client{})
		} else {
			fetcher.FetchPost(&http.Client{}, line)
		}
	}
}