fonchain-fiee/pkg/common/tools.go
2025-02-20 19:43:50 +08:00

65 lines
1.5 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package common
import (
"dubbo.apache.org/dubbo-go/v3/common/constant"
"fmt"
"fonchain-fiee/pkg/e"
"os"
)
type Result struct {
IP string `json:"ip"`
Location Location `json:"location"`
AdInfo AdInfo `json:"ad_info"`
}
type Location struct {
Lat float64 `json:"lat"`
Lng float64 `json:"lng"`
}
type AdInfo struct {
Nation string `json:"nation"`
Province string `json:"province"`
City string `json:"city"`
District string `json:"district"`
AdcodE int `json:"adcode"`
}
type IpResult struct {
Status int `json:"status"`
Message string `json:"message"`
RequestID string `json:"request_id"`
Result Result `json:"result"`
}
type IPDict struct {
fileData []byte //文件数据
offset uint32 //当前下标定位
firstOffset uint32 //第一条IP记录的偏移地址
lastOffset uint32 //最后一条IP记录的偏移地址
totalIPNum uint32 //IP记录的总条数不包含版本信息记录
}
type IPLocation struct {
IP string `json:"ip"`
BeginIP string `json:"begin_ip"`
EndIP string `json:"end_ip"`
Country string `json:"country"`
Area string `json:"area"`
}
func GetConf() (iniConf string, err error) {
if os.Getenv(e.MODE_ENV) != "" {
if err = os.Setenv(constant.ConfigFileEnvKey, fmt.Sprintf("./conf/%s/%s", os.Getenv(e.MODE_ENV), e.SERVER_DUBBOGO_CONFIG)); err != nil {
return
}
}
if os.Getenv(e.MODE_ENV) == "" {
iniConf = fmt.Sprintf("../conf/%s", e.SERVER_CONFIG)
} else {
iniConf = fmt.Sprintf("./conf/%s/%s", os.Getenv(e.MODE_ENV), e.SERVER_CONFIG)
}
return
}