mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-20 07:21:26 +02:00
breaking: move maxmind config to config.providers
- moved maxmind to separate module - code refactored - simplified test
This commit is contained in:
31
internal/maxmind/instance.go
Normal file
31
internal/maxmind/instance.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package maxmind
|
||||
|
||||
import (
|
||||
"github.com/yusing/go-proxy/internal/gperr"
|
||||
"github.com/yusing/go-proxy/internal/task"
|
||||
)
|
||||
|
||||
var instance *MaxMind
|
||||
|
||||
func SetInstance(parent task.Parent, cfg *Config) gperr.Error {
|
||||
newInstance := &MaxMind{Config: cfg}
|
||||
if err := newInstance.LoadMaxMindDB(parent); err != nil {
|
||||
return err
|
||||
}
|
||||
if instance != nil {
|
||||
instance.task.Finish("updated")
|
||||
}
|
||||
instance = newInstance
|
||||
return nil
|
||||
}
|
||||
|
||||
func HasInstance() bool {
|
||||
return instance != nil
|
||||
}
|
||||
|
||||
func LookupCity(ip *IPInfo) (*City, bool) {
|
||||
if instance == nil {
|
||||
return nil, false
|
||||
}
|
||||
return instance.lookupCity(ip)
|
||||
}
|
||||
Reference in New Issue
Block a user