Пример #1
0
func (middleware *offlinemiddleware) TestTruncate() {
	dbFile := middleware.replaydb.GetDBFilePath()
	middleware.replaydb.Close()
	fmt.Println("DB file ", dbFile)
	db, err := os.OpenFile(dbFile, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, os.ModePerm)
	if err != nil {
		fmt.Println("OPen error ", err)
	}
	err = db.Truncate(0)
	if err != nil {
		fmt.Println("Truncate error ", err)
	}
}
Пример #2
0
func (middleware *offlinemiddleware) Truncate(w http.ResponseWriter) {
	dbFile := middleware.replaydb.GetDBFilePath()
	middleware.replaydb.Close()
	db, err := os.OpenFile(dbFile, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, os.ModePerm)
	if err != nil {
		w.WriteHeader(500)
		w.Write([]byte(err.Error()))
		log.Println("OPen error ", err)
	}
	err = db.Truncate(0)
	if err != nil {
		w.WriteHeader(500)
		w.Write([]byte(err.Error()))
		log.Println("Truncate error ", err)
	}
	w.WriteHeader(200)
	w.Write([]byte("<h1>Truncate successful</h1>"))
}