Exemple #1
0
func testStart() {
	fmt.Println("starting in test mode - test.db database recreated")
	lib.TraceStart("logs/test.log")
	// lib.TraceStart("stdout")
	os.Remove("db/test.db")
	d.DataStart("db/test.db")
}
Exemple #2
0
func prodStart() {
	fmt.Println("starting in production mode")
	now := time.Now()
	_, mth, day := now.Date()
	traceFile := fmt.Sprintf("logs/%v%d_%02d%02d%02d.log", mth.String()[0:3], day, now.Hour(), now.Minute(), now.Second())
	lib.TraceStart(traceFile)
	d.DataStart("db/prod.db") // init global memory data vars, load data, start data dispatch goroutine
	go schedule.Scheduler()
}
Exemple #3
0
func main() {
	var err error

	lib.TraceStart("stdout")
	dbName := "datafiles/test1.db"
	if err = os.Remove(dbName); err != nil {
		log.Fatal(err)
	}
	d.DataStart(dbName)

	bk1 := d.Book{BookName: "book1", AccessCode: "ab1cd"}
	resultChan := d.Data("addBook", &bk1)
	result := <-resultChan
	bookid := result.Val.(string)
	log.Println("bookid=", bookid)

	tb1 := d.Tab{Bookid: bookid, TabName: "tab1", TabNumber: 10}
	resultChan = d.Data("addTab", &tb1)
	result = <-resultChan
	tabid := result.Val.(string)
	log.Println("tabid=", tabid)

	noteids := make([]string, 0, 10)
	for i := 0; i < 3; i++ {
		note := new(d.Note)
		note.Content = "note content " + strconv.Itoa(i)
		note.When = time.Now()
		note.Mono = true
		noteParms := d.NoteParms{Bookid: bookid, Tabid: tabid, Previd: d.Zeroid, Note: note}
		resultChan = d.Data("addNote", &noteParms)
		if result = <-resultChan; result.Status != d.DataOk {
			log.Fatal(result.Val.(string))
		}
		noteids = append(noteids, result.Val.(string))
	}

	rand.Seed(time.Now().UnixNano()) // rand used by common.RandCode

	doneChan = make(chan string)

	//lib.TraceLevel(9)

	go writeLoop(bookid, tabid, noteids)

	//time.Sleep(1 * time.Second)

	go readLoop(bookid, tabid)

	done1 := <-doneChan
	log.Println(done1)

	done2 := <-doneChan
	log.Println(done2)

	log.Println("main end")
}