コード例 #1
0
func main() {
	flag.Parse()

	os.Remove(dbPath)
	db, err := db.NewDB(dbPath)
	if err != nil {
		log.Fatalf("Could not open database: %v", err)
	}

	if err := db.SetUp(); err != nil {
		log.Fatalf("Could not set up database: %v", err)
	}

	if err := db.SeedData(); err != nil {
		log.Fatalf("Could not seed database: %v", err)
	}

	var timestamps []timestamp.Timestamp
	if err := db.AllTimestamps(&timestamps); err != nil {
		log.Fatalf("Could not fetch timestamps: %v", err)
	}
	fmt.Println("Found timestamps:")
	for _, t := range timestamps {
		fmt.Printf("  %v\n", time.Unix(t.SecondsSinceEpoch, 0).Format(time.UnixDate))
	}
}
コード例 #2
0
// SetUp initializes the database
func SetUp(path string) error {
	innerdb, err := db.NewDB(path)
	if err != nil {
		return err
	}
	globalDB = &dbWrapper{innerdb}
	return nil
}