2020-07-17 09:05:25 +08:00
|
|
|
package app
|
|
|
|
|
|
|
|
import (
|
2020-07-17 09:41:09 +08:00
|
|
|
"path/filepath"
|
2020-07-17 10:52:36 +08:00
|
|
|
|
2021-08-02 12:01:25 +08:00
|
|
|
db2 "github.com/zu1k/nali/internal/db"
|
|
|
|
|
|
|
|
"github.com/zu1k/nali/internal/constant"
|
|
|
|
|
2020-07-17 09:05:25 +08:00
|
|
|
geoip2 "github.com/zu1k/nali/pkg/geoip"
|
2020-07-21 06:19:52 +08:00
|
|
|
"github.com/zu1k/nali/pkg/ipip"
|
2020-07-17 09:05:25 +08:00
|
|
|
"github.com/zu1k/nali/pkg/qqwry"
|
2020-07-21 06:19:52 +08:00
|
|
|
"github.com/zu1k/nali/pkg/zxipv6wry"
|
2020-07-17 09:05:25 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2021-08-02 12:01:25 +08:00
|
|
|
db []db2.IPDB
|
2020-07-17 09:05:25 +08:00
|
|
|
qqip qqwry.QQwry
|
|
|
|
geoip geoip2.GeoIP
|
|
|
|
)
|
|
|
|
|
2021-08-02 12:01:25 +08:00
|
|
|
// InitIPDB init ip database content
|
|
|
|
func InitIPDB(ipdbtype db2.IPDBType) {
|
|
|
|
db = make([]db2.IPDB, 1)
|
2020-07-17 11:37:03 +08:00
|
|
|
switch ipdbtype {
|
2021-08-02 12:01:25 +08:00
|
|
|
case db2.GEOIP2:
|
2020-07-18 09:52:59 +08:00
|
|
|
db[0] = geoip2.NewGeoIP(filepath.Join(constant.HomePath, "GeoLite2-City.mmdb"))
|
2021-08-02 12:01:25 +08:00
|
|
|
case db2.QQIP:
|
2020-07-18 09:52:59 +08:00
|
|
|
db[0] = qqwry.NewQQwry(filepath.Join(constant.HomePath, "qqwry.dat"))
|
2021-08-02 12:01:25 +08:00
|
|
|
db = append(db, zxipv6wry.NewZXwry(filepath.Join(constant.HomePath, "ipv6wry.database")))
|
|
|
|
case db2.IPIP:
|
2020-07-21 06:19:52 +08:00
|
|
|
db[0] = ipip.NewIPIPFree(filepath.Join(constant.HomePath, "ipipfree.ipdb"))
|
2021-08-02 12:01:25 +08:00
|
|
|
db = append(db, zxipv6wry.NewZXwry(filepath.Join(constant.HomePath, "ipv6wry.database")))
|
2020-07-17 09:05:25 +08:00
|
|
|
}
|
|
|
|
}
|