zabov/00.database.go

59 lines
1.2 KiB
Go
Raw Normal View History

2020-10-08 22:14:07 +02:00
package main
import (
"fmt"
"os"
"github.com/syndtr/goleveldb/leveldb"
)
//MyZabovKDB is the storage where we'll put domains to block (obsolete)
//var MyZabovKDB *leveldb.DB
2020-10-08 22:14:07 +02:00
//MyZabovCDB is the storage where we'll put domains to cache (global for all configs)
2020-10-08 22:14:07 +02:00
var MyZabovCDB *leveldb.DB
//MyZabovKDBs is the storage where we'll put domains to block (one for each config)
var MyZabovKDBs map[string]*leveldb.DB
2020-10-08 22:14:07 +02:00
func init() {
var err error
os.RemoveAll("./db")
os.MkdirAll("./db", 0755)
/*
MyZabovKDB, err = leveldb.OpenFile("./db/killfile", nil)
if err != nil {
fmt.Println("Cannot create Killfile db: ", err.Error())
} else {
fmt.Println("Killfile DB created")
}*/
2020-10-08 22:14:07 +02:00
MyZabovCDB, err = leveldb.OpenFile("./db/cache", nil)
2020-10-08 22:14:07 +02:00
if err != nil {
fmt.Println("Cannot create Cache db: ", err.Error())
2020-10-08 22:14:07 +02:00
} else {
fmt.Println("Cache DB created")
2020-10-08 22:14:07 +02:00
}
MyZabovKDBs = map[string]*leveldb.DB{}
}
// ZabovCreateKDB creates Kill DBs
func ZabovCreateKDB(conf string) {
var err error
dbname := "./db/killfile_" + conf
KDB, err := leveldb.OpenFile(dbname, nil)
2020-10-08 22:14:07 +02:00
if err != nil {
fmt.Println("Cannot create Killfile db: ", err.Error())
2020-10-08 22:14:07 +02:00
} else {
fmt.Println("Killfile DB created")
2020-10-08 22:14:07 +02:00
}
MyZabovKDBs[conf] = KDB
2020-10-08 22:14:07 +02:00
}