2017-09-03 04:50:31 +00:00
|
|
|
package main
|
|
|
|
|
2019-04-20 04:55:22 +00:00
|
|
|
import c "github.com/Azareal/Gosora/common"
|
2017-09-03 04:50:31 +00:00
|
|
|
import "github.com/oschwald/geoip2-golang"
|
|
|
|
|
2019-04-20 04:55:22 +00:00
|
|
|
var geoipDB *geoip.DB
|
|
|
|
var geoipDBLocation = "geoip_db.mmdb"
|
2017-09-03 04:50:31 +00:00
|
|
|
|
|
|
|
func init() {
|
2019-04-20 04:55:22 +00:00
|
|
|
c.Plugins.Add(&c.Plugin{UName: "geoip", Name: "Geoip", Author: "Azareal", Init: initGeoip, Deactivate: deactivateGeoip})
|
2017-09-03 04:50:31 +00:00
|
|
|
}
|
|
|
|
|
2019-04-20 04:55:22 +00:00
|
|
|
func initGeoip(plugin *c.Plugin) (err error) {
|
|
|
|
geoipDB, err = geoip2.Open(geoipDBLocation)
|
2017-09-03 04:50:31 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-04-20 04:55:22 +00:00
|
|
|
func deactivateGeoip(plugin *c.Plugin) {
|
|
|
|
geoipDB.Close()
|
2017-09-03 04:50:31 +00:00
|
|
|
}
|