Initial commit (code only without large binaries)
This commit is contained in:
24
EdgeDNS/internal/models/region_resolver.go
Normal file
24
EdgeDNS/internal/models/region_resolver.go
Normal file
@@ -0,0 +1,24 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/iplibrary"
|
||||
"net"
|
||||
)
|
||||
|
||||
var DefaultRegionResolver = &RegionResolver{}
|
||||
|
||||
type RegionResolver struct {
|
||||
}
|
||||
|
||||
func (this *RegionResolver) Resolve(ip net.IP) (countryId int64, provinceId int64, cityId int64, providerId int64) {
|
||||
var result = iplibrary.Lookup(ip)
|
||||
if result != nil && result.IsOk() {
|
||||
countryId = result.CountryId()
|
||||
provinceId = result.ProvinceId()
|
||||
cityId = result.CityId()
|
||||
providerId = result.ProviderId()
|
||||
}
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user