From 38458cc4d0de6f074b7585dd76d03b7ef3c4f3f4 Mon Sep 17 00:00:00 2001 From: Dreamacro <305009791@qq.com> Date: Tue, 31 Dec 2019 12:30:42 +0800 Subject: [PATCH] Migration: change geoip address --- Dockerfile | 4 +--- config/initial.go | 38 ++++++-------------------------------- 2 files changed, 7 insertions(+), 35 deletions(-) diff --git a/Dockerfile b/Dockerfile index bd0d05c9..ba3c66cd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,7 @@ FROM golang:alpine as builder RUN apk add --no-cache make git && \ - wget http://geolite.maxmind.com/download/geoip/database/GeoLite2-Country.tar.gz -O /tmp/GeoLite2-Country.tar.gz && \ - tar zxvf /tmp/GeoLite2-Country.tar.gz -C /tmp && \ - mv /tmp/GeoLite2-Country_*/GeoLite2-Country.mmdb /Country.mmdb + wget -O /Country.mmdb https://github.com/Dreamacro/maxmind-geoip/releases/latest/download/Country.mmdb WORKDIR /clash-src COPY . /clash-src RUN go mod download && \ diff --git a/config/initial.go b/config/initial.go index 63ff427f..e151e74c 100644 --- a/config/initial.go +++ b/config/initial.go @@ -1,56 +1,30 @@ package config import ( - "archive/tar" - "compress/gzip" "fmt" "io" "net/http" "os" - "strings" C "github.com/Dreamacro/clash/constant" "github.com/Dreamacro/clash/log" ) func downloadMMDB(path string) (err error) { - resp, err := http.Get("http://geolite.maxmind.com/download/geoip/database/GeoLite2-Country.tar.gz") + resp, err := http.Get("https://github.com/Dreamacro/maxmind-geoip/releases/latest/download/Country.mmdb") if err != nil { return } defer resp.Body.Close() - gr, err := gzip.NewReader(resp.Body) + f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY, 0644) if err != nil { - return + return err } - defer gr.Close() + defer f.Close() + _, err = io.Copy(f, resp.Body) - tr := tar.NewReader(gr) - for { - h, err := tr.Next() - if err == io.EOF { - break - } else if err != nil { - return err - } - - if !strings.HasSuffix(h.Name, "GeoLite2-Country.mmdb") { - continue - } - - f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY, 0644) - if err != nil { - return err - } - defer f.Close() - _, err = io.Copy(f, tr) - if err != nil { - return err - } - } - - return nil + return err } // Init prepare necessary files