func main() { port := ":8080" router := lgwm_api.NewRouter() lgwm_api.GlobalDB = lgwm_api.NewBoltDB("lgwm.db", "BlogPosts", 0777, &bolt.Options{Timeout: 1 * time.Second}) // defer db.Close() if err := lgwm_api.GlobalDB.Open(); err != nil { log.Fatalf("%v", err) } log.Printf("Database opened.") log.Printf("Starting API Server on %s...", port[1:]) // Listen on port. log.Fatal(http.ListenAndServe(port, router)) }
func main() { databaseName := "lgwm.db" bucketName := "BlogPosts" var err error db := lgwm.NewBoltDB(databaseName, bucketName, 0777, &bolt.Options{Timeout: 1 * time.Second}) err = db.Open() defer db.Close() if err != nil { log.Fatalf("%v\n", err) } log.Printf("Database opened...") log.Printf("Retrieving json blog posts from stdin...") gi, err := reap.Import(os.Stdin) if err != nil { log.Fatalf("%v\n", err) } posts := gi.GetPublishedPosts() for id, p := range posts { log.Printf("Importing Post %d, '%s'", p.ID, p.Title) postAsBytes, err := json.Marshal(p) if err != nil { log.Fatalf("%v\n", err) } err = AddPost(db, bucketName, strconv.Itoa(id), postAsBytes) if err != nil { log.Fatalf("%v\n", err) } } log.Printf("Import Completed.") }