Skip to content

Commit

Permalink
Find ipipfree.ipdb in the same directory as the executable, if the op…
Browse files Browse the repository at this point in the history
…en file is empty
  • Loading branch information
Delphier committed Mar 18, 2020
1 parent f77bf57 commit f269481
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion ipip.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"io/ioutil"
"log"
"net/http"
"os"
"path/filepath"
"strings"

"github.com/ipipdotnet/ipdb-go"
Expand All @@ -20,7 +22,7 @@ var (
func Open(file string) (err error) {
if DB == nil {
if file == "" {
file = "ipipfree.ipdb"
file = filepath.Join(getExeDir(), "ipipfree.ipdb")
}
DB, err = ipdb.NewCity(file)
if err != nil {
Expand Down Expand Up @@ -69,3 +71,8 @@ func trim(result []string) (s string) {
}
return
}

func getExeDir() string {
s, _ := os.Executable()
return filepath.Dir(s)
}

0 comments on commit f269481

Please sign in to comment.