Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

打了包 setenv也不行,找不到dat路径,放到项目根目录也不行 #56

Open
54huige opened this issue Sep 28, 2023 · 4 comments

Comments

@54huige
Copy link

54huige commented Sep 28, 2023

有啥好办法不,必须设置系统变量才行吗?

@sndnvaps
Copy link

sndnvaps commented Sep 29, 2023

@54huige
需要定义PHONE_DATA_DIR这个环境变量,才行,在这个变量的目录里面,需要放置phone.dat文件
如果不想设置变量,可以直接修改源代码的https://github.com/xluohome/phonedata/blob/master/phonedata.go#L53

func init() {
        //注释掉这几行
	//dir := os.Getenv("PHONE_DATA_DIR")
	//if dir == "" {
		//_, fulleFilename, _, _ := runtime.Caller(0)
		//dir = path.Dir(fulleFilename)
	//}
	var err error
	content, err = ioutil.ReadFile("/root/phone.dat") //在这里直接修改为你的dat文件路径,
	if err != nil {
		panic(err)
	}
	total_len = int32(len(content))
	firstoffset = get4(content[INT_LEN : INT_LEN*2])
}

@sndnvaps
Copy link

sndnvaps commented Oct 1, 2023

@sndnvaps @xluohome 强烈建议增加360接口号段数据, 因为360接口数据较为准确, (虽然一些免费接口号段数据量不会很多) 曾用360号段数据进行过对比, 发现还是360号段归属地准确

这得找@xluohome才行

@xluohome
Copy link
Owner

xluohome commented Oct 27, 2023 via email

@fivenull
Copy link

可以修改文件phonedata.go

func init() {
	//dir := os.Getenv("PHONE_DATA_DIR")
	var err error
	dir, err := os.Getwd()
	if err != nil {
		dir = os.Getenv("PHONE_DATA_DIR")
	}
	if dir == "" {
		_, fulleFilename, _, _ := runtime.Caller(0)
		dir = path.Dir(fulleFilename)
	}

	content, err = ioutil.ReadFile(path.Join(dir, PHONE_DAT))
	if err != nil {
		panic(err)
	}
	total_len = int32(len(content))
	firstoffset = get4(content[INT_LEN : INT_LEN*2])
}

然后把phone.dat丢到打包文件的同级目录,就可以正常运行了,我测试是无误的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants