fix: geoip mmdb/geodata init

This commit is contained in:
metacubex
2023-01-09 21:07:31 +08:00
parent b4503908df
commit e9a7e104c0
6 changed files with 101 additions and 92 deletions

View File

@ -2,6 +2,9 @@ package mmdb
import (
"github.com/oschwald/geoip2-golang"
"io"
"net/http"
"os"
"sync"
C "github.com/Dreamacro/clash/constant"
@ -42,3 +45,20 @@ func Instance() *geoip2.Reader {
return mmdb
}
func DownloadMMDB(path string) (err error) {
resp, err := http.Get(C.MmdbUrl)
if err != nil {
return
}
defer resp.Body.Close()
f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY, 0o644)
if err != nil {
return err
}
defer f.Close()
_, err = io.Copy(f, resp.Body)
return err
}