first commit

This commit is contained in:
何昌清
2026-03-26 22:13:03 +08:00
parent bbe1faa363
commit a2685f7f1e
51 changed files with 11244 additions and 0 deletions

37
utils/geoip_util.go Normal file
View File

@@ -0,0 +1,37 @@
// Package utils/geoip_util.go
package utils
import (
"sync"
"github.com/oschwald/geoip2-golang"
)
var (
geoDB *geoip2.Reader
geoOnce sync.Once
)
// InitGeoIP 初始化 GeoIP 数据库
func InitGeoIP(geoDBPath string) error {
var err error
geoOnce.Do(func() {
if geoDBPath != "" {
geoDB, err = geoip2.Open(geoDBPath)
}
})
return err
}
// GetGeoIP 获取 GeoIP 实例
func GetGeoIP() *geoip2.Reader {
return geoDB
}
// CloseGeoIP 关闭 GeoIP 数据库
func CloseGeoIP() error {
if geoDB != nil {
return geoDB.Close()
}
return nil
}