Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
wwqgtxx committed Sep 9, 2024
1 parent 952e193 commit 5c8f305
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
28 changes: 14 additions & 14 deletions component/mmdb/mmdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,24 @@ const (
var (
//go:embed Country.mmdb
EmbedMMDB []byte
IPreader IPReader
IPonce sync.Once
ipReader IPReader
ipOnce sync.Once
)

func LoadFromBytes(buffer []byte) {
IPonce.Do(func() {
ipOnce.Do(func() {
mmdb, err := maxminddb.FromBytes(buffer)
if err != nil {
log.Fatalln("Can't load mmdb: %s", err.Error())
}
IPreader = IPReader{Reader: mmdb}
ipReader = IPReader{Reader: mmdb}
switch mmdb.Metadata.DatabaseType {
case "sing-geoip":
IPreader.databaseType = typeSing
ipReader.databaseType = typeSing
case "Meta-geoip0":
IPreader.databaseType = typeMetaV0
ipReader.databaseType = typeMetaV0
default:
IPreader.databaseType = typeMaxmind
ipReader.databaseType = typeMaxmind
}
})
}
Expand All @@ -64,25 +64,25 @@ func Verify() bool {
}

func IPInstance() IPReader {
IPonce.Do(func() {
ipOnce.Do(func() {
mmdb, err := getMmdbReader()
if err != nil {
log.Fatalln("Can't load MMDB: %s", err.Error())
}
IPreader = IPReader{Reader: mmdb}
ipReader = IPReader{Reader: mmdb}
switch mmdb.Metadata.DatabaseType {
case "sing-geoip":
IPreader.databaseType = typeSing
ipReader.databaseType = typeSing
case "Meta-geoip0":
IPreader.databaseType = typeMetaV0
ipReader.databaseType = typeMetaV0
default:
IPreader.databaseType = typeMaxmind
ipReader.databaseType = typeMaxmind
}
})

return IPreader
return ipReader
}

func ReloadIP() {
mihomoOnce.Reset(&IPonce)
mihomoOnce.Reset(&ipOnce)
}
2 changes: 1 addition & 1 deletion config/initial.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

func downloadMMDB(path string) (err error) {
resp, err := http.Get("https://cdn.jsdelivr.net/gh/Dreamacro/maxmind-geoip@release/Country.mmdb")
resp, err := http.Get("https://cdn.jsdelivr.net/gh/Loyalsoldier/geoip@release/Country.mmdb")
if err != nil {
return
}
Expand Down

0 comments on commit 5c8f305

Please sign in to comment.