mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-18 22:49:52 +02:00
fix(acl): maxmind error even if configured, refactor
This commit is contained in:
@@ -1,12 +1,29 @@
|
||||
package maxmind
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/yusing/go-proxy/internal/gperr"
|
||||
"github.com/yusing/go-proxy/internal/notif"
|
||||
"github.com/yusing/go-proxy/internal/task"
|
||||
)
|
||||
|
||||
var instance *MaxMind
|
||||
|
||||
var warnOnce sync.Once
|
||||
|
||||
func warnNotConfigured() {
|
||||
log.Warn().Msg("MaxMind not configured, geo lookup will fail")
|
||||
notif.Notify(¬if.LogMessage{
|
||||
Level: zerolog.WarnLevel,
|
||||
Title: "MaxMind not configured",
|
||||
Body: notif.MessageBody("MaxMind is not configured, geo lookup will fail"),
|
||||
Color: notif.ColorError,
|
||||
})
|
||||
}
|
||||
|
||||
func SetInstance(parent task.Parent, cfg *Config) gperr.Error {
|
||||
newInstance := &MaxMind{Config: cfg}
|
||||
if err := newInstance.LoadMaxMindDB(parent); err != nil {
|
||||
@@ -22,6 +39,7 @@ func HasInstance() bool {
|
||||
|
||||
func LookupCity(ip *IPInfo) (*City, bool) {
|
||||
if instance == nil {
|
||||
warnOnce.Do(warnNotConfigured)
|
||||
return nil, false
|
||||
}
|
||||
return instance.lookupCity(ip)
|
||||
|
||||
Reference in New Issue
Block a user